Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually failing a build after it's complete

Tags:

jenkins

Is it possible to set the build result for a build after that build is complete?

I could not find any plugins that do this already, and I was considering writing my own, but I wanted to see if this was even possible before going down that path.

(I have looked at existing code and how the "Fail The Build" plugin works as an example, but my understanding of the Jenkins code base is not advanced enough to understand what all the possibilities are.)

Use case: we have a build pipeline, and near the end of the pipeline there is a deploy-to-qa step that deploys the artifact to a QA environment. We have automated tests before this step to try to catch any problems with the artifact, but our test coverage is not very high in some areas so bugs could still slip through the cracks. I'd like to have the ability to mark a deploy-to-qa build as FAILED after the fact, to denote that that particular pipeline was invalid and is not a candidate for production release. (Basically the same as this Build Pipeline Plugin issue)

like image 697
jaustin Avatar asked Oct 18 '12 20:10

jaustin


2 Answers

I have an untested suggestion: Make a parametrized build, where the parameter determines if build will fail or not (for example simple bat / shell script testing the parameter from the environment variable it sets, and doing exit 0 or exit 1). This assumes that build pipelines manually triggered step will ask the parameters, and not use default values.

If it does not support interactive build parameters, then some other way is needed to tell this extra build step wether it should fail or not. Maybe editing upstream build description or display name to indicate failure, and then allowing build pipeline to continue to this extra build step, which probably has to use system groovy script to dig out upstream build description or display name.

like image 27
hyde Avatar answered Oct 06 '22 21:10

hyde


After some more investigation in the code, I believe that this is not possible.

From hudson.model.Run:

public void setResult(Result r) {
    // state can change only when we are building
    assert state==State.BUILDING;

    // snip
    ...
}

So the build result cannot change except when in "building" state.

I could try to muck with the lastSuccessful and lastStable symlinks (as is done with the delete() function in hudson.model.AbstractBuild), but then those would be reset as soon as Jenkins reloaded the build results from jobs/JOBNAME/builds/.

like image 123
jaustin Avatar answered Oct 06 '22 22:10

jaustin