Chris B.
Chris B.

Reputation: 90191

How do I run a task on failure in Jenkins?

I've got a Jenkins job that is intended to do the following:

  1. Build a project and deploy it to a test server
  2. Run tests
  3. If the tests fail, roll back the server to the previous version
  4. If the tests succeed, update the version in our source control system

Because we have a single test server, we need to ensure that Jenkins is only running a single version of this job at a time. Unfortunately, we can't seem to find a way to run a job on failure and keep the upstream job from executing while the downstream job is running.

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

Upvotes: 12

Views: 16754

Answers (2)

Paul Hicks
Paul Hicks

Reputation: 13999

The Jenkins Post Build Task allows you to run tasks in a job after failure. Rolling the server back sounds more like a task than a job, so that might suit.

Otherwise, there are a couple of plugins that allow for more complex pipelining features. The Pipeline Plugin seems to be the most popular at the moment.

Upvotes: 9

Slav
Slav

Reputation: 27485

In job configuration, under Advanced Project Options (just before the SCM part), click the Advanced... button. You can now chose to Block build when upstream/downstream is executing

As for running conditional steps on failure:
- Use Post Build Tasks as Paul suggested, or
- Configure logic using Conditional Build steps

Upvotes: 0

Related Questions