Dynamically Fill Jenkins Choice Parameter With Git Branches In a Specified Repo

后端 未结 13 914
离开以前
离开以前 2020-11-29 16:41

I have a parameterized Jenkins job which requires the input of a specific Git branch in a specific Git repo. Currently this parameter is a string parameter.

Is ther

13条回答
  •  独厮守ぢ
    2020-11-29 17:30

    expanding on @malenkiy_scot's answer. I created a new jenkins job to build up the file that is used by Extended Choice Plugin.

    you can do the following (I did it as execute shell steps in jenkins, but you could do it in a script):

    git ls-remote git@github.com:my/repo.git |grep refs/heads/* >tmp.txt
    sed -e 's/.*refs\/heads\///' tmp.txt > tmp2.txt
    tr '\n' ',' < tmp2.txt > tmp3.txt
    sed '1i\branches=' tmp3.txt > tmp4.txt
    tr -d '\n'  < tmp4.txt > branches.txt
    

    I then use the Artifact deployer plugin to push that file to a shared location, which is in a web url, then just use 'http://localhost/branches.txt' in the Extended Choice plugin as the url. works like a charm.

提交回复
热议问题