Jenkins Multibranch Pipelines - Configuring properties in branches?

ぐ巨炮叔叔 提交于 2019-12-08 02:01:14

问题


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?

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.

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.

Installed Versions:

  • Jenkins version: 2.19.4
  • Multibranch Pipeline Plugin version: 2.9.2

回答1:


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)

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.



来源:https://stackoverflow.com/questions/41160794/jenkins-multibranch-pipelines-configuring-properties-in-branches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!