Jenkins多分支管道-配置分支中的属性? [英] Jenkins Multibranch Pipelines - Configuring properties in branches?

查看:239
本文介绍了Jenkins多分支管道-配置分支中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经成功使用Jenkins Multibranch Pipeline插件成功建立了构建管道,该插件在大多数情况下都有效,但是这个问题困扰着我们:Jenkinsfile包含一组属性,这些属性也会显示出来在用户界面中,但是如何为各个分支设置默认值?

We have successfully set up a build pipeline using the Jenkins Multibranch Pipeline Plugin, which works great most of the time, but we have this problem which nags us: The Jenkinsfile contains a set of properties, and these also show up in the UI, but how can I set up default values for individual branches?

这是我们的Jenkinsfile中的属性定义的样子:

This is how the properties definitions look like in our Jenkinsfile:

properties([
    parameters([
        string(defaultValue: 'somevalue', description: 'Some description', name: 'SOME_VALUE'),
        string(defaultValue: 'asdfasdfasdfasdfdasdasdasdasd...', description: 'Client ID', name: 'TEST_CLIENT_ID'),
        // ... more properties
        string(defaultValue: '', description: 'Enter non-empty value to skip tests', name: 'SKIP_TESTS'),
    ]), 
    [$class: 'RebuildSettings', autoRebuild: true, rebuildDisabled: false],
    pipelineTriggers([])
])

每个分支构建管道都有一个显示配置"(管道是自动生成的),并且在执行带参数构建"时可以输入值,但是似乎无法保存分支默认值?根本没有保存"按钮.

I do have a "Show Configuration" for each branch build pipeline (pipelines are generated automatically), and I can enter values when doing a "Build with parameters", but I can't seem to save the branch default values? There simply is no "Save" button for that.

我们是否对Jenkins进行了错误配置,还是我在其他地方这样做?我要实现的是能够在每个分支的基础上定义属性的默认值.

Have we misconfigured Jenkins, or do I do this somewhere else? What I want to achieve is to be able to define default values for properties on a per-branch basis.

已安装的版本:

  • Jenkins版本:2.19.4
  • Multibranch Pipeline插件版本:2.9.2

推荐答案

您可以将表格与双引号字符串一起使用

You can use the form with the double-quoted string

string(defaultValue: "branch-${env.GIT_BRANCH}", description: 'Some description', name: 'SOME_VALUE')

设置参数的默认值(如您在问题中所述)

in setting the default values of the parameters (as you describe in your question)

受以下事实的限制:在一个版本中执行属性"步骤时,它将设置出现在下一个版本中的参数默认值.这是因为参数输入是在Jenkinsfile可用之前完成的.

It's limited by the fact that when the 'properties' step is executed in one build, it sets the parameter defaults that appear on the next build. This is because the parameter entry is done before the Jenkinsfile is even available.

这篇关于Jenkins多分支管道-配置分支中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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