Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - How to run post-build action without re-running the job?

I have a lengthy Jenkins job with a failing post-build action.

How can I repeatedly run the post-build action without re-running the whole job?

like image 895
Craig Avatar asked Mar 03 '13 22:03

Craig


2 Answers

If splitting the job into 2 jobs is not an option, you may consider
https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin
(this is pre-installed with Jenkins I believe). This will make the "promotion" steps a separate and repeatable process. You can configure it to run automatically after build, and then manually on demand when needed.

If your post-build steps require access to build artifacts, you will need to use https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin to copy the build artifacts to the promotion's workspace.

Another solution is to skip build step based on parameter. Have a Choice parameter called SkipBuild or something. Set the possible values to TRUE/FALSE, default to FALSE

In your Build step, before actually building, check if SkipBuild is set to TRUE. If TRUE, exit 0, if FALSE (which is default) then run build command.

This way, automatic Build executions will always run the Build step. But you can also manually run the build and select "SkipBuild=TRUE" to skip the build step and go straight to post-build actions. If you need to skip some post-build actions, you would need to implement this SkipBuild parameter there as well.

Careful however as subsequent executions of the build, even with "SkipBuild=TRUE" will still perform an SVN checkout, so your workspace may change.

like image 88
Slav Avatar answered Sep 23 '22 06:09

Slav


Depending on what your build steps are, you might be able to 'skip' them.

For example, my build steps are powershell and windows batch files.

If I want to skip a step I simply add 'exit 0' as the first line of the powershell or batch command.

Be aware this WILL still result in other pre-build steps, like workspace cleanup and scm checkouts being run.

like image 22
Stuart Whelan Avatar answered Sep 25 '22 06:09

Stuart Whelan