Search code examples
jenkins-pipelinesalt-project

How to restrict only one parameter in jenkins pipeline?


I have the below pipeline script with string parameters. The Target parameter will fail if multiple comma separated inputs (target1, target2) are provided in Jenkins. How can I restrict the Jenkins pipeline to accept just one parameter (target) as parameter and not multiple comma separated values.

properties([
  parameters([
    string(defaultValue: '', description: '', name: 'ID'),
    string(defaultValue: '', description: '', name: 'Target')
  ])
])

Solution

  • What you could do in the first stage/step

    if ((params.Target.split(',')).size() > 1) {
        error("Build failed because of this and that..")
    }