jenkins-pipeline - Jenkinsfile - 一种跳过整个管道的方法?

标签 jenkins-pipeline

我使用 declarative syntax用于开发( 多分支 )管道脚本,我正在寻找一种方法来 根据某些条件跳过整个管道 ,无需修改 when在每一个阶段。

当前用例:我正在设置一个 cron在晚上触发构建,但我只想说分支 release/v1develop晚上要通过管道,而不是其他十几个分支。

triggers {
  cron('H 21 * * 1-5')
}

// SKIP PIPELINE if triggered by timer AND branch not 'release/v1' OR 'develop'

stages {
  stage('build') {
    when { ... }
  }
  stage('UT') {
    when { ... }
  }
etc...
}

任何提示将不胜感激。

最佳答案

如果您有管道定义插件 1.3 或更高版本 ( changelog ),则可以嵌套阶段。

使用它,您可以将整个工作嵌套在父阶段中,并在父阶段使用 when 指令。如果跳过父阶段,将跳过所有子阶段。下面是一个例子:

pipeline {
    agent any
    stages {
        stage('Parent') {
            when {
                //...
            }
            stages {
                stage('build') {
                    steps {
                        //..
                    }
                }
                stage('UT') {
                    steps {
                        //...
                    }
                }
            }
        }
    }
}

关于jenkins-pipeline - Jenkinsfile - 一种跳过整个管道的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55633505/

相关文章:

docker - 如何停止 Jenkinsfile 中正在运行的容器?

if-statement - 有条件的 Jenkins 管道作业

python - 使用 Jenkinsfile 在 "sidecar"模式下运行两个 docker 容器

jenkins - 从另一个 Jenkinsfile 调用远程 jenkins 文件

Jenkins 管道中的 Docker 代理卷安装未按预期工作

amazon-web-services - aws key 和 Secret 在 aws cli 上工作但在 jenkins 上不起作用

windows - Jenkinsfile windows cmd 输出变量引用

node.js - 如何将 jenkins 管道与 nvm 包装器插件一起使用?

jenkins - 无法在 Github 多分支管道上按名称过滤

jenkins - 如何屏蔽 Jenkins Pipeline 项目中的密码字段?