Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a task on failure in Jenkins?

Tags:

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?

like image 942
Chris B. Avatar asked May 08 '14 20:05

Chris B.


People also ask

How do I run a failed job in Jenkins?

To retry a Jenkins job, you can use the Naginator plugin. Simply install the plugin, and then check the Post-Build action "Retry build after failure" on your project's configuration page. If the build fails, it will be rescheduled to run again after the time you specified.

How do you resolve build failure in Jenkins?

Go to the project page and Click on the failed build number from the 'Build History'. Look for the details: File at which the ERROR has occured, ERROR details. Then Click Workspace on the left and go to the specified file location.

What happens if build fails in Jenkins?

The Build Failure Analyzer Jenkins plugin analyzes the causes of failed builds and presents the causes on the build page. It does this by using a knowledge base of build failure causes maintained from scratch.

How do I ignore failed stage in Jenkins pipeline?

To ignore a failed step in declarative pipeline you basically have two options: Use script step and try-catch block (similar to previous proposition by R_K but in declarative style)


1 Answers

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.

like image 189
Paul Hicks Avatar answered Sep 30 '22 12:09

Paul Hicks