Get previous build result

I want to imitate Jenkins’s original behavior of doing things (like sending notifications) when assemblies become unstable / fail or become successful again.

To do this, I need to request the previous build status, which can be done as follows:

currentBuild.rawBuild.getPreviousBuild()?.getResult().toString()

However, it rawBuildmust be a “dangerous” object and thus blacklisted and cannot be executed inside the Groovy sandbox .

Now, since I am loading my Jenkins scripts from SCM, I am unable to deactivate the Groovy sandbox at the level of each project, but only for the whole Jenkins instance (i.e. through this ), and this, of course, is not what I want.

Is there any other way to determine the last build status of a job that conforms to the sandbox principles (and does not include hacks, such as requesting status via the Jenkins REST API) that I skipped?

+4
source share
2 answers

No need to refer to rawBuild, instead you can do the following without any special permissions:

currentBuild.getPreviousBuild().result

This will allow you to see the result of the previous build without requiring any special privileges set by the Jenkins administrator. It should be available anywhere.

Pipeline API Link: https://qa.nuxeo.org/jenkins/pipeline-syntax/globals#currentBuild

: https://support.cloudbees.com/hc/en-us/articles/217591038-How-to-Iterate-Through-the-Last-Successful-Builds-in-Pipeline-Job

+2

getRawBuild Jenkins > Script RejectedAccessException , , groovy.

getRawBuild, getPreviousBuild getResult script.

+4

Source: https://habr.com/ru/post/1659062/


All Articles