marherbi
marherbi

Reputation: 361

Repository and Branches as parameters in Jenkins

I Want to create a JOB that have as parameters the name of the repository, and once this parameter is set, then the second parameter (branches) is shown as list of available GIT branches in the selected repository.

Thank for your help. Reda.

Upvotes: 1

Views: 596

Answers (1)

Javier C.
Javier C.

Reputation: 8267

You can get these parameters using this Groovy code:

  1. Get repository name:

    def rpository_name = scm.getUserRemoteConfigs()[0].getUrl().tokenize('/')[3].split("\\.")[0]
    
  2. Get list branches:

    def branches = git for-each-ref refs/heads/ --format='%(refname:short)'
    

If this code is not working you can use this script: Jenkins groovy script which lists remote branches. Raw

Upvotes: 1

Related Questions