How to dynamically get list of branches or pull requests in Jenkinsfile/groovy?

542 views
Skip to first unread message

Mark Stosberg

unread,
Aug 7, 2017, 1:49:40 PM8/7/17
to Jenkins Users
Currently I've got an input() call in my Jenkinsfile that prompts users to select a branch name to manually deploy:

  userInput = input(
   id: 'userInput', message: 'Manual Deploy?', parameters: [
   [$class: 'ChoiceParameterDefinition', choices: 'develop\nmaster\nPR-124', description: 'Branch to deploy', name: 'branch', defaultValue: 'develop'],
  ])

Instead of hardcoding a list branch names, how can I dynamically build this list based on the list of the pull requests that are already known to Jenkins in our multlbranch pipeline configuration?

Jenkins is configured to automatically build new pull requests already. 

Thanks,

      Mark

Stephen Connolly

unread,
Aug 8, 2017, 4:00:50 AM8/8/17
to jenkins...@googlegroups.com
You'd best be served by writing a plugin with a step...

Start from the code for resolveScm and you should be able to modify that to return a list of branch names rather than the current behaviour of returning a scm instance for a specific named branch (resolveScm will have a delta from what you want but it should have the smallest delta)

--
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/a0c15c4e-805c-4a41-bdf6-9cf42014b23e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

Danny Rehelis

unread,
Aug 8, 2017, 7:22:39 AM8/8/17
to jenkins...@googlegroups.com
Check this plugin - https://wiki.jenkins.io/display/JENKINS/Git+Parameter+Plugin
If you may change your build behavior from user input to parameter, this plugin might serve you well.

Reply all
Reply to author
Forward
0 new messages