Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all branches/jobs of a multibranch pipeline job?

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.

like image 654
Schubidu Avatar asked Oct 22 '25 14:10

Schubidu


1 Answers

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;
}
like image 98
Schubidu Avatar answered Oct 24 '25 04:10

Schubidu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!