0

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.

agabrys
  • 8,728
  • 3
  • 35
  • 73
user124
  • 423
  • 2
  • 7
  • 26
  • I was asked at work how to do it, so I prepared a script: https://stackoverflow.com/q/67370232/4944847. I didn't extend my answer in this thread, because here the main question was how to get available methods. – agabrys May 03 '21 at 14:31

1 Answers1

1

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}"
}
agabrys
  • 8,728
  • 3
  • 35
  • 73
  • thanks.It helps. Can you tell me one thing. In the jenkins class, how can I seethe return type of "instance" variable ?I mean , "Jenkins.instance"? – user124 Apr 30 '21 at 05:55
  • `Jenkins.instance` in Groovy is the same as `Jenkins.getInstance()` in Java. So you are interested in this method declaration: [jenkins.model.Jenkins#getInstance](https://javadoc.jenkins.io/jenkins/model/Jenkins.html#getInstance--) – agabrys Apr 30 '21 at 10:26
  • ok got it. I have not used groovy before. Is there a rule like Jenkins.instance is interprated as means Jenkins.getInstance() ? Becasue method calling is done like ClassName.Function as in code i shraed build.getTime() etc., – user124 Apr 30 '21 at 12:08
  • Getters and setters in Groovy are described here: https://groovy-lang.org/style-guide.html#_getters_and_setters. You may replace `obj.getTime()` by `obj.time`, `obj.isFoo()` by `obj.foo` and `obj.setBar(value)` by `obj.bar = value`. – agabrys Apr 30 '21 at 18:22