Search code examples
apijenkinsbuildlabeljenkins-api

Jenkins APIs for getting the build custom labels


Is there any API available from jenkins to get all builds custom label for a specific job set by 'Set Build Name'? If it is achievable thru some programmatic scripts to get these custom build labels list for a job, please share the ideas if APIs are not available.


Solution

  • build-name-setter-plugin changes the display name of the AbstractBuild object. what you can do is get all the builds of the specific job, and compare their display names to the job's display name. for example:

    jenkins = Jenkins.getInstance()
    job = jenkins.getItem(jobName)
    blds = job.getBuilds()
    def result = blds.findAll { it.displayName!=job.displayName}
    println result