With some experimenting I think I have gotten what I need.
def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def jenkinsProject = "multiBranchPipelineProjectA/master"
def project = jenkinsInstance.getItemByFullName(jenkinsProject)
def job = project.getAllJobs().first()
def lastBuild = job.getLastBuild()
def completed = !lastBuild.isBuilding()

Method getAllJobs() returns only one Job. Why is that?
I guess that if I called getAllJobs on the Multibranch pipeline project I 
would get for all branches (for instance 4 branches = 4 jobs).

onsdag 3. august 2016 11.14.33 UTC+2 skrev Sverre Moe følgende:
>
> Have Jenkins projects as Multibranch pipeline:
> org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject
>   extends jenkins.branch.MultiBranchProject
>     extends com.cloudbees.hudson.plugins.folder.computed.ComputedFolder
>       extends com.cloudbees.hudson.plugins.folder.AbstractFolder
>         extends hudson.model.AbstractItem
>
> I need to get the latest build job in my Groovy build script. Jenkins 
> Javadoc is available online, but other APIs are not. It makes it difficult 
> to know which methods I have access to.
>
> WorkflowMultiBranch does not extend AbstractProject which has easy access 
> methods such getLastBuild() or getLastCompletedBuild(). Not having access 
> to the Javadoc for Cloudbees or Branch-API I am unsure if such a method 
> exists for either MultiBranchProject, ComputedFolder or AbstractFolder.
> Go searching through the source code for access methods is tedious and 
> time consuming.
>
> MultiBranchProject: 
> https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java
> ComputedFolder: 
> https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java
> AbstractFolder: 
> https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java
>
> Anyway that is what I was forced to do with no access to such Javadocs.
> Could not find any such easy access methods as those in hudson.model.Job 
> or hudson.model.AbstractProject.
>
> Can get all jobs from AbstractItem
> public abstract Collection<? extends Job> getAllJobs()
> And pick the first in the list (if the first is the latest build).
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/24574a4f-b80c-43f6-be95-f54b4935e4f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to