Jenkins- Not getting desired options while using Active Choice and Active Choicec Reactive Parameter

Viewed 524

We have requirement to select Environment from Jenkins UI to run the feature files.

Different Environment Options: QA, UAT, PROD

On the basis of the Environment selection from drop-down, all the available tenants i.e. different servers associated with that Environment should be visible.

To achieve above purpose I've used "Active Choices Parameter" for Environment.

  • Name: "Environment"
  • Groovy Script: return ['QA','UAT']
  • Fallback Script: return['error']
  • Choice Type: Single Select

To select the server or tenant on the basis of Environment selection, I've used "Active Choices Reactive Parameter"

  • Name: Tenants
  • Groovy Script:
return ['http://node-1.nginx.portal.daa-1.can.qa.aws.abc.net/login':'CAN','http://node-1.nginx.portal.daa-1.wan.qa.aws.abc.net/login':'WAN']
} else if (Environment.equals("UAT")) {
return ['https://can.uat.daa.app/login':'CANUAT','https://blic.uat.daa.app/login':'BLIC']
}
 else if (Environment.equals("PROD")){
return ['http://node-1.nginx.portal.daa-1.can.qa.aws.abc.net/login':'CANPROD','http://node-1.nginx.portal.daa-1.blic.qa.aws.abc.net/login':'BLIC']
} else {
  return ["Unknown"]
}
  • Fallback Script: return['error']
  • Choice Type: Single Select

After applying and saving this configuration, I'm getting ERROR in the Tenants drop-down. Seems making minor mistake but unable to catch it.

Getting ERROR in the drop-down of Tenant Option

1 Answers

Environment should be prefaced with a '$' (as in $Environment) in the groovy script to signify it is a variable.

And did you specify the 'Referenced parameters' as 'Environment' in the Active Choices Reactive Parameter settings?:

referencedParameters: 'Environment',

You can test out your groovy script in the script console at http://your-jenkins-server/script

Related