Jenkins Pipeline 上的动态参数取决于分支

Win*_*ins 4 jenkins jenkins-pipeline

我的詹金斯管道上有类似的东西

properties([
    parameters([
        booleanParam(description: 'Merge master to this branch', name: 'merge_master', defaultValue: false),
        someOtherParameters
    ])
])
Run Code Online (Sandbox Code Playgroud)

显然,如果管道在主分支上运行,则第一个参数没有意义。那么,只有当管道不在 master 分支上运行时,我怎样才能拥有这个参数呢?

hak*_*iri 5

如果您还没有找到方法,您可以像这样有条件地将元素添加到参数列表中

def list = []
if (env.BRANCH_NAME != 'master') {
    list.add(booleanParam(description: 'Merge master to this branch', name: 'merge_master', defaultValue: false))
}
//example list.add(otherParams)
//finally
properties([parameters(list)])
Run Code Online (Sandbox Code Playgroud)

有关在 groovy 中添加到列表的更多信息,请参见此处