2

I am looking for an option for multibranch pipeline where Jenkinsfile should disable/enable a Jenkins UI parameter based on git branch name.

parameters {
        string(name: 'Cloud', defaultValue: 'AWS', description: 'Cloud Type')
}

But this will show parameter always, I want to show this option only for 'main' branch but not for 'test' branch. How to achieve this? Is this possible to achieve without using 'Active Choices' plugins? Thanks in advance

Krishna
  • 501
  • 1
  • 8
  • 17

1 Answers1

2

Use the following syntax to set the Parameters, which will give you more flexibility.

if ("$BRANCH_NAME".contains("main")) {
    properties([
        parameters([
            string(name: 'Cloud', defaultValue: 'AWS', description: 'Cloud Type')
        ])
    ])
} else {
    println "If not set something different"
}


pipeline {
    agent any
    stages {
        stage("Hello") {
            steps {
                echo "Building Something"
            }
        }
    }
}
ycr
  • 12,828
  • 2
  • 25
  • 45