根据 Jenkins 文档 referenced在这里,为了确保在特定阶段定义的 docker 代理在管道中定义的同一节点上运行,必须将标志重用节点设置为 true。
reuseNode A boolean, false by default. If true, run the container on the node specified at the top-level of the Pipeline, in the same workspace, rather than on a new node entirely.This option is valid for docker and dockerfile, and only has an effect when used on an agent for an individual stage.
对于声明性,这可以使用
agent {
docker {
image 'gradle-java:0.0.1'
reuseNode true
}
}
但是,我无法找到有关如何在脚本化管道中进行设置的任何示例。
有人可以帮助如何在脚本化管道中实现这一目标吗?
最佳答案
在新版本的声明式管道中,它得到了增强并建议使用 label
agent {
docker {
image 'maven:3-alpine'
label 'my-defined-label'
args '-v /tmp:/tmp'
}
}
如果您想对脚本化管道执行相同操作,请在 node(agentName)
中提及代理标签名称。 ,它会像node("my-defined-label") {
docker.image('maven:3-alpine').inside('-v $HOME/.m2:/root/.m2') {
stage('Build') {
sh 'mvn -B'
}
}
}
关于jenkins - 脚本化的 Jenkinsfile Docker 代理,如何指定重用节点标志,是否需要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50829491/