3

Is there a way to get the names of all branches that the scan of a multibranch pipeline job has gathered?

I would like to set up a nightly build with dependencies on existing build jobs and therefore need to check if the multibranch jobs contain some certain branches. An other way would be to check for an existing job.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Schubidu
  • 195
  • 1
  • 15

1 Answers1

5

I found a way by using the Jenkins API.

In case anyone else is having this question: here is my groovy solution: (Critics and edits welcome)

import java.util.ArrayList
import hudson.model.*;

def ArrayList<String> call(String pipelineName) {

    def hi = hudson.model.Hudson.instance;
    def item = hi.getItemByFullName(pipelineName);
    def jobs = item.getAllJobs();

    def arr = new ArrayList<String>();

    Iterator<?> iterator = jobs.iterator();
    while (iterator.hasNext()) {
        def job = iterator.next();
        arr.add(pipelineName + "/" + job.name);
    }
    return arr;
}
Schubidu
  • 195
  • 1
  • 15
  • Is this the only way to achieve this? Is there any builtin way to get this info? – red888 Dec 18 '17 at 20:56
  • @red888 I could not find any other way and this seems like a build in way to me because it uses the jenkins api. – Schubidu Jan 12 '18 at 11:12