或此脚本管道版本
node {
withDockerContainer(image: 'debian:stable', args: '-v /var/run/docker.sock:/var/run/docker.sock') {
stage("first") {
sh 'bash --version'
}
node {
stage("second") {
sh "bash --version"
}
}
}
}
在这条管道中,我们希望第二阶段以与根,docker的不同代理运行。但是,这个第二阶段的步骤从未运行,至少在詹金斯设置我的公司正在运行的情况下。
一些日志:Pull request #17677 updated
...
[Pipeline] Start of Pipeline
[Pipeline] milestone
Trying to pass milestone 51
[Pipeline] node
Running on jenkins-agent-n2-custom-8-32768-hswu4b
in /tmp/....
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: git
using credential github-blablacarbot-ssh
Fetching changes from the remote Git repository
Fetching without tags
...
[GitHub Checks] GitHub check (name: Jenkins, status: in_progress) has been published.
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . debian:stable
.
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withDockerContainer
jenkins-agent-n2-custom-8-32768-hswu4b does not seem to be running inside a container
$ docker run -t -d -u 0:0 -v /var/run/docker.sock:/var/run/docker.sock -w ... debian:stable cat
$ docker top c67eb42eef77ae16fce698c21eabbcb14d8e6591130429ce2413bd57dc7e02f8 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (On root agent)
[Pipeline] sh
+ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (On other agent)
[Pipeline] node
Running on jenkins-agent-n2-custom-8-32768-8cbh5v
in /tmp...
[Pipeline] {
[Pipeline] checkout
The recommended git tool is: git
...
[GitHub Checks] GitHub check (name: Jenkins, status: in_progress) has been published.
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
process apparently never started in /tmp/...
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 c67eb42eef77ae16fce698c21eabbcb14d8e6591130429ce2413bd57dc7e02f8
$ docker rm -f --volumes c67eb42eef77ae16fce698c21eabbcb14d8e6591130429ce2413bd57dc7e02f8
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code -2
[GitHub Checks] GitHub check (name: Jenkins, status: completed) has been published.
GitHub has been notified of this commit’s build result
Finished: FAILURE
为什么在第二代理中无法开始的过程?
在现实生活中,我正在为性能目的探索此选项:我的大多数阶段都可以在同一代理上运行(因此,让我们使用root One阶段,以便不必为每个阶段弹出一个新的阶段) ,但是在另一个代理商中孤立的跑步阶段可以受益。
我记得遇到了同样的问题,甚至认为它在某个时间之前正在工作。事实证明,在不同代理商上运行管道jenkins的管道(至少是根据文档
)只提供了两个选项:
agent none
:
agent none
agent none
部分。
REUSENODE
使用一些代理,但不能使用agent
块。可以将其与docker { ... }
优化资源分配和性能相结合:
a布尔,默认情况下是错误的。如果为true,请在管道顶部指定的节点上运行容器,在同一工作空间中,而不是完全在新节点上。此选项对
reuseNode
和,因此只有在您不需要运行Docker容器中的大部分阶段时才有意义:docker
有效,只有在用于单个阶段的代理时才有效。
我也建议不要使用,因为它使构建环境未知,最终可能导致错误而不可重现的构建。
dockerfile
所以,您的管道看起来像这样:
agent any
或这样 - 但这会浪费遗嘱执行人
pipeline {
agent none
stages {
stage('On standard agent') {
agent {
docker {
label 'standard'
image 'debian:stable'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
steps {
sh 'bash --version'
}
}
stage('On other agent') {
agent {
docker {
label 'other'
image 'some-other-image:1.0.0'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
steps {
sh '''
bash --version
'''
}
}
}
}