声明式Jenkinspipe道和Docker
刚开始看Jenkins声明式pipe道并在Docker容器中运行我的构build。 我有一个项目,通过git拉npm包,因此需要设置ssh密钥。
从我遇到过,我可以设置构build参数,如--build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)"
,然后在我的Dockerfile
ARG ssh_pub_key
我在Jenkins文件中采取了以下方法
pipeline { agent { dockerfile { args '''--build-arg ssh_prv_key="$(cat /var/lib/jenkins-git/.ssh/id_rsa)"''' } } stages { stage('Test') { steps { sh 'echo $ssh_prv_key' } } } }
在Jenkins中运行构build时,我在构build图像时得到了下面的输出(没有提到--build-arg
。
docker build -t 085eb412f6dd28c1a7843aa9f9ed84e7c4af3e1b -f Dockerfile .
并没有为variables
我没有正确设置它们吗? 有没有人以不同的方式处理密钥的复制?
谢谢
UPDATE
我的Jenkinsfile现在看起来像下面但不会运行得到
Required context class hudson.FilePath is missing Perhaps you forgot to surround the code with a step that provides this, such as: node
似乎我不能在pipe道声明之外运行任何脚本?
def ssh_prv_key = sh script: 'cat /var/lib/jenkins-git/.ssh/id_rsa', returnStdout: true def ssh_pub_key = sh script: 'cat /var/lib/jenkins-git/.ssh/id_rsa.pub', returnStdout: true pipeline { agent { dockerfile { args """--build-arg ssh_prv_key=\"${ssh_prv_key}\" --build-arg ssh_pub_key=\"${ssh_pub_key}\" """ } } stages { stage('Test') { steps { sh 'echo $ssh_prv_key' } } } }
这里$(cat /var/lib/jenkins-git/.ssh/id_rsa)
是一个shell命令。
AFAIK,绑定必须在stream水线之外声明,以在定义代理时使用它们。
因此,使pipe道工作参数化。
- 添加
ssh_prv_key
作为凭证参数 。 - select
Secretfile
- 将默认值设置为上传密文件
- 重复
ssh_pub_key
步骤
然后在dockerfile
additionalBuildArgs
指令中使用ssh_prv_key
。
pipeline { agent { dockerfile { additionalBuildArgs ""--build-arg ssh_prv_key=\"$ssh_prv_key\" --build-arg ssh_pub_key=\"$ssh_pub_key\"" } } stages { stage('Test') { steps { sh "echo $ssh_prv_key" } } } }
- Windows中的Docker中的Jenkins目标中的错误
- 通过npm install – Docker Container访问private git repos
- dockerized Jenkins在运行jestunit testing时崩溃了
- 我如何更改maven中的serenity-bdd日志设置
- 在当地jenkins CIbuild立一个项目,并将该项目部署到Digital Ocean等远程服务器
- 纳金服务器与jenkins和巧克力的容器
- 在Jenkinsdocker实例上找不到节点
- jenkinsfiledocker代理访问私人存储库和composer php
- 在Jenkins中调用Git在Docker中构build脚本