jenkinsjenkins-pluginsjenkins-groovyjenkins-job-dslhudson-plugins

How to get Jenkins build history in a Groovy script? Which information are available for every build?


I have a groovy script that runs as a shared library and get jenkins build details.

projects = Jenkins.instance.getJob('ABB').getItems()

for( build in projects.getAllJobs())
{
 //process build data
  build.getDuration();
  build.getTime();
  etc.

}

Can some one tell me how I can see all the get methods (all metadata related to build) that I can access by using the build variable? Is there any Javadoc for this? I am not able to find? As of now it access Duration and Time but I want to know what all info can I get.


Solution

  • Yes, Jenkins provides Javadoc: https://javadoc.jenkins.io/

    build is an instance of the hudson.model.Run interface.

    Of course the instance may provide more details because every type of job (FreeStyle, Pipeline etc.) may return an object with more details. For example new pipelines use org.jenkinsci.plugins.workflow.job.WorkflowRun.

    The easiest option is to check the class and next search for its Javadoc :)

    for (def build in projects.allJobs) {
        echo "${build.class}"
    }