How to run a task on failure in Jenkins?

I have a Jenkins job that is designed to do the following:

  • Create a project and deploy it to the test server
  • Running tests
  • If tests fail, roll back the server to a previous version
  • If the tests are successful, update the version in our version control system.

Since we have one test server, we need to make sure that Jenkins only works with one version of this work at a time. Unfortunately, we cannot find a way to complete the task in the event of a failure and keep the upstream task running while the task is running downstream.

Is there an easy way to do this? Is there a better way?

+7
jenkins
source share
2 answers

Jenkins Post Build Task allows you to run tasks in a task after a crash. Rolling back a server sounds more like a task than a task, so this might work.

Otherwise, there are several plugins that allow you to create more complex pipeline functions. Pipeline Plugin seems to be the most popular at the moment.

+5
source share

In the job configuration, in the Advanced project settings section (immediately before the SCM part), click the Advanced ... button. Now you can select Block build when upstream/downstream is executing

Regarding starting conditional steps on failure:
- Use Publish build tasks as suggested by Paul, or
- Customize logic using Conditional build steps

0
source share

All Articles