Joe
Joe

Reputation: 126

get git repository from multi pipelines jobs with groovy script

I have 200-300 jobs of multibranchPipelineJob , I want to to create all of them with DSL.

I have this script to get the job name

    for(job in      Hudson.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob)
     ) { 
      println job.fullName 
    }

it gives me the job name , but I can't figure out how to get the git repository from it. any idea ?

Upvotes: 2

Views: 1268

Answers (1)

Vitalii Vitrenko
Vitalii Vitrenko

Reputation: 10405

In Multibranch pipeline project only the top level job contains information about a repository. So you should iterate over WorkflowMultiBranchProject instead of WorkflowJob.

This way you can get a repository URL and a List of RefSpecs.

for(job in Hudson.instance.getAllItems(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)) { 
      def repositoryUrl = job.SCMSources[0].remote
      def refSpecs = job.SCMSources[0].refSpecs
}

Note that this is applied only for GIT repositories. For SVN it would be slightly different.

Upvotes: 2

Related Questions