Par*_*ram 5 jenkins docker terraform jenkins-pipeline
我正在创建用于在Docker容器上运行Terraform的Jenkins管道。
这是我的管道脚本。
pipeline {
agent {
docker {
image 'hashicorp/terraform:full'
args '--entrypoint=/bin/bash'
}
}
stages {
stage('execute') {
steps {
sh 'terraform --version'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在詹金斯上运行此管道时,出现以下错误。
$ docker run -t -d -u 995:993 --entrypoint=/bin/bash -w /var/lib/jenkins/workspace/terraform -v /var/lib/jenkins/workspace/terraform:/var/lib/jenkins/workspace/terraform:rw,z -v /var/lib/jenkins/workspace/terraform@tmp:/var/lib/jenkins/workspace/terraform@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** hashicorp/terraform:full cat
$ docker top a0b801d657d0fffdfa95c387564128b130ab1d28569ad59bd0151c8b7faf6ffd -eo pid,comm
java.io.IOException: Failed to run top 'a0b801d657d0fffdfa95c387564128b130ab1d28569ad59bd0151c8b7faf6ffd'. Error: Error response from daemon: Container a0b801d657d0fffdfa95c387564128b130ab1d28569ad59bd0151c8b7faf6ffd is not running
Run Code Online (Sandbox Code Playgroud)
好像詹金斯(Jenkins)添加了一条cat命令来运行图像hashicorp / terraform:full。
注意,我已经使用--entrypoint = / bin / bash覆盖了/ bin / bash的入口点,因为hashicorp / terraform:full已经定义了一个入口点。
S.S*_*ker 12
我必须将 更改ENTRYPOINT为空以禁用 terraform 容器定义中的入口点定义。而且我认为该light图像足以执行 terraform。
我使用以下脚本使其工作:
pipeline {
agent {
docker {
image 'hashicorp/terraform:light'
args '--entrypoint='
}
}
stages {
stage('execute') {
steps {
sh 'terraform --version'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎是 jenkins 中 docker-workflow-plugin 的默认行为。\n[已修复 JENKINS-41316] 将“inside”切换回 CMD,检测入口点是否设计不当 #116 https://github.com/ jenkinsci/docker-workflow-plugin/pull/116
\n\n\n\n\n我们运行图像指定的任何进程(甚至 sh -c)\n 它们的目的是\n
\nThat will break in most images, since for this purpose we need to start a container, pause it while we exec some stuff, and then stop it, without having to guess what its \xe2\x80\x9cmain command\xe2\x80\x9d might run and when it might exit on its own. That is why we cat (I also have considered sleep infinity or some POSIX-compliant variant).
https://issues.jenkins-ci.org/browse/JENKINS-39748
\n\n\n\n他们希望容器 /* 期望挂起直到被杀死 */。
\n\n原答案:
\n\n您是否尝试在没有 -d 选项的情况下运行(这意味着在后台运行)
\n\ndocker run -it --entrypoint=/bin/bash hashicorp/terraform:full\nRun Code Online (Sandbox Code Playgroud)\n\n然后你就可以进入容器来运行你想要的任何东西了。
\n\n以nginx为例:
\n\ndocker run -it --entrypoint=/bin/bash nginx\nroot@e4dc1d08de1d:/# ls\nbin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var\nroot@e4dc1d08de1d:/# cat /var/log/\napt/ btmp dpkg.log faillog lastlog nginx/ wtmp\nroot@e4dc1d08de1d:/# cat /var/log/faillog\nroot@e4dc1d08de1d:/#\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1157 次 |
| 最近记录: |