How to access certificate files (certificate and private key) from credentials manager (dockerCert/ x.509 client certificate)

Hello everyone,

I have a Jenkins pipeline which starts up a docker container to execute some tests in it.
Now I need to install a client certificate with private key on that docker container.
Therefore I used the Jenkins credential manager and created a x.509 client certificate credential entry with the certificate and the private key containing.

In my pipeline, I know I can inject the credential by using this:
withCredentials([dockerCert(credentialsId: ‘keystore’, variable: ‘DOCKER_CERT_PATH’)]) {
// script which starts up the container and works with the credentials
}

But my problem is, that I don’t know how to actually access my certificate and private key through DOCKER_CERT_PATH. The documentation here is very unclear to me: Credentials Binding Plugin
It says for “dockerCert”:
variable : String
Name of an environment variable to be set during the build.
Its value will be the absolute path of the directory where the {ca,cert,key}.pem files will be created.
You probably want to call this variable DOCKER_CERT_PATH, which will be understood by the docker client binary.
credentialsId : String
Credentials of an appropriate type to be set to the variable.

As I understand, there are cert.pem and key.pem automatically created on the certificate path stored in DOCKER_CERT_PATH. Is that correct?
If I try to copy a pem file to the docker container, I get an error.

I use this script:
withCredentials([dockerCert(credentialsId: ‘keystore’, variable: ‘DOCKER_CERT_PATH’)]) {

sudo docker run …

sudo docker cp $DOCKER_CERT_PATH/cert.pem myContainerName:/usr/local/share/ca-certificates/cert.pem

}

The console output looks like this:

sudo docker cp ***/cert.pem myContainerName:/usr/local/share/ca-certificates/cert.pem
“docker cp” requires exactly 2 arguments.
See ‘docker cp --help’.
Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH_DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

How can I use the DOCKER_CERT_PATH here? It is masked, so it is not recognized as a path.

Thanks in advance for your help