有条件地启用Jenkins声明性管道选项吗? [英] Conditionally enable Jenkins declarative pipeline options?

查看:63
本文介绍了有条件地启用Jenkins声明性管道选项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins是否提供任何功能来实现下面描述的以下管道?

Does Jenkins provide any functionality to achieve the following pipeline described below?

pipeline
{
    agent any
    options
    {
        when {
            branch 'master'
        }
        disableConcurrentBuilds()
    }
    stages { ... }
}

对于该单一管道必须管理的存储库,我有两种状态:

I have two states for repositories which this single pipeline must manage:

  1. 构建提交以提交到合并请求分支(预合并),允许构建同时运行
  2. 在合并请求的合并( post-merge )上构建master分支,不允许同时运行构建.
  1. Build for commits to merge-requests branches (pre-merge), allow builds to be run concurrently
  2. Build the master branch on merge of merge-requests (post-merge), do not allow builds to be run concurrently.

推荐答案

您可以使用

You can use the Lockable Resources Plugin to guarantee that the problematic steps do not run in parallel when on the master branch.

类似的东西:

stage('on master') {
    when {
        branch 'master'
    }
    steps {
        lock(label: 'choose_a_label') {
            // your steps
        }
    }
}


stage('not on master') {
    when {
        not {
            branch 'master'
        }
    }
    steps {
        // your steps
    }
}

这篇关于有条件地启用Jenkins声明性管道选项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆