jenkins - 脚本化的 Jenkinsfile Docker 代理,如何指定重用节点标志,是否需要?

标签 jenkins jenkins-plugins jenkins-pipeline

根据 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/

相关文章:

groovy - Jenkinsfile 是纯 Groovy 中的吗?在 Jenkinsfile 的 `steps` 中使用了什么 Groovy 语言构造?

python - 在 Jenkins 主目录之外导入模块

html - Jenkins 从 API 触发作业

Jenkins CI 管道脚本不允许使用方法 groovy.lang.GroovyObject

jenkins - 当构建过程被时间触发时,在 Jenkins 中设置 BUILD_USER

jenkins - 列出脚本化的Jenkins Pipeline中正在使用的插件

java - Jenkins + Maven 发布插件 : release:branch + Git - Unable to commit files

jenkins - Jenkins 的 Gerrit 触发器安装

Jenkins Groovy 插件文件未找到异常

jenkins - 如何在具有一个或多个 SCM 的 Jenkins 工作流程中找到罪魁祸首或提交者