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

后端 未结 13 927
离开以前
离开以前 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:38

    I was able to achieve this result using the Jenkins Dynamic Parameter Plug-in. I used the Dynamic Choice Parameter option and, for the choices script, I used the following:

    proc1 = ['/bin/bash', '-c', "/usr/bin/git ls-remote -h ssh://user@server.com/path/to/repo.git"].execute()
    proc2 = ['/bin/bash', '-c', "awk '{print \$2}'"].execute()
    proc3 = ['/bin/bash', '-c', "sed s%^refs/heads%origin%"].execute()
    
    all = proc1 | proc2 | proc3
    String result = all.text
    
    String filename = "/tmp/branches.txt"
    boolean success = new File(filename).write(result) 
    
    def multiline = "cat /tmp/branches.txt".execute().text
    def list = multiline.readLines()
    

提交回复
热议问题