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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With