Jenkins Post Build Step – Execute Script

To execute a post-build script in Jenkins

Install Post Build Task Plugin
By going to Dashboard -> Manage Jenkins -> Manage Plugins -> Available -> Filter -> “Post build task”

Yes, the UI kind of sucks, anyone wants to contribute to Jenkins by improving the UX/UI design? =)

To configure the step

Go to your Jenkins job
Click Configure
Look for “Add post-build action”
Select “Post build task”
post build task

Now, the plugin looks for STRING MATCHES in the console output of the build. (I am only highlighting this because I had a typical RTFM case this morning)
So, if you want to execute the task when a specific event happens, you need it to look for that event’s output in the console log. Let’s say the output that signifies failure is this: “Build step ‘Execute Windows batch command’ marked build as failure”. You can add the substring “marked build as failure” as my Log Text, like so:
build step

You can use the AND and OR operation to perform the same script in multiple cases (such as different exceptions).

Leave a Reply

Your email address will not be published. Required fields are marked *