Jenkins declarative pipeline dynamic paramters

22 views
Skip to first unread message

Mike Zupan

unread,
Aug 29, 2017, 12:08:05 PM8/29/17
to Jenkins Users
I have a use case where we need to list environments to run a pipeline over and we have multiple jenkins servers that handle different environments. 

jenkins1 handles dev1 dev2 dev3
jenkins2 handles prod1 prod2 prod3

I want to be able to setup a pipeline that sources different envs and shows them as a choice field. 

Try one was setting a global env var in the jenkins config like

ENVS="dev1\ndev2\ndev3"

when I did

pipeline {
    parameters {
      choice(choices: "${env.ENVS}", description: 'What Environment?', name: 'env')
    }
}

It removed the \ so it shows it as a single choice as dev1ndev2ndev3

I'd also be open to having it read a file outside the workspace where ansible can put like /etc/env_list and the pipeline can read that file in but I wasn't haven't any luck with that. 

I'm open to trying anything to make it work!

Thanks!

Slide

unread,
Aug 29, 2017, 12:22:42 PM8/29/17
to Jenkins Users
Could you do something like this?

ENVS="dev1|dev2|dev"


pipeline {
  parameters {
    choice(choices: "${env.ENVS.replace('|', '\n')}", description: 'What Environment?', name: 'env')
  }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8275681d-af79-41bb-b852-f0008e3fc0af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages