[英]Passing jenkins secrets file to docker image run
I'm building a Jenkins pipeline, I've a builde image in my repo, and I've uploaded a secret file that I need to provide to my building job to Jenkins credentials as a Secret file.我正在构建一个 Jenkins 管道,我在我的存储库中有一个构建图像,并且我已经上传了一个我需要提供给我的构建作业的秘密文件到 Jenkins 凭据作为一个秘密文件。 I need to copy this file to the working directory of a docker run command that run a command on the builder image.我需要将此文件复制到 docker 运行命令的工作目录中,该命令在构建器映像上运行命令。 I'm using this to retrieve the file as env variable:我正在使用它来检索文件作为 env 变量:
withCredentials([
file(credentialsId: 'keystore', variable: 'KEYSTORE'), {
try {
docker run parameters ${image} -e ${KEYSTORE} command...
}
Any ideas on how can I make that file available inside the container when run the docker image?关于在运行 docker 映像时如何使该文件在容器内可用的任何想法?
If you want to get the credentials file inside a docker container, you'll also need to volume mount it.如果您想在 docker 容器中获取凭证文件,您还需要对其进行卷挂载。
docker run parameters ${image} -e ${KEYSTORE} -v ${KEYSTORE}:${KEYSTORE}:ro
In case you use the built-in docker support, jenkins will take care of that:如果您使用内置的 docker 支持,jenkins 将负责:
pipeline {
agent {
dockerfile {
dir 'build'
}
}
stages {
stage('Build') {
steps {
withCredentials([file(credentialsId: 'keystore', variable: 'KEYSTORE')]) {
sh 'ls -l'
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.