Is there a way to resume from a failed job in Jenkins? - jenkins

I am using 4 Jenkin jobs for Continuous Build and Deployment.The jobs are created for label creation, build using the label, deploy to server1 and deploy to server2 and so on..
The Create_label build will run the MYSQL query in database and get the label. Create_label job on success will invoke the Build-job with the label and upon successful completion of Build-Job, it will invoke Deploy-server1 job and so on..
If the build fails in Build-Job and after that If I start the 1st Create-Label job then it runs the job and creates the NEW label. I mean running the create-label every time will get you incremental label. I can only get the label from 1st job and then pass to 2nd job. Can anyone suggest how to resume from the failed job with out running the first job and start with second job using the old label created(from the last build in 1st job). any work around to accomplish this type of situation in jenkins.
1.Create-Label
2.Build-Job
3.Deploy-server1
4.Deploy-server2

So it seems, you have 2 issue at the moment:
Issue 1 --> If any job fails, the next time it should skip the successful jobs and restart only from the failed job.
Probable Solution --> You could use Build Pipeline plugin, https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin , and if the job fails at say second job, then all you have to do is restart the second job from the pipeline and it would continue from there.
Issue 2 --> For job 2, you not only want to restart it but have to take the input, Label Number, from the previous successful job 1, without restarting job 1
Unfortunately, I don't have a clean automated solution for this. The only thing I can think of requires manual intervention, i.e. since this job is parameterized, change the default value of the parameter to the Label Number from the last successful job 1 before restarting it from plugin(The above plugin doesn't ask for parameters while running the job)
or let Job1 login the label number in some centralized location and let job B take the parameter from there instead of taking it from jobA.
Thanks,
Manish Joshi

I am using MultiJob plugin and you can always just click "Resume build" in the parent job to continue from a failed job.
And in this case the parameters for its execution will be all the same as on those previous run which failed.

Related

Remove unnecessary jobs from build pipeline on Jenkins

I'm a bit new to Jenkins and I'm having an display issue with Build Pipeline plugin. I'm executing some jobs in parallel using JobFanIn Plugin, i.e. the next job in the pipeline will only be executed when all the previous jobs are concluded. However, the Build Plugin believes that all jobs will trigger a new instance of the last job. The execution goes right, but the display isn't.
Bellow is possible to observe what is happening in practice. The GENERATE TEST REPORT job will only be triggered when all TEST jobs are finished and this occurs ok. But since the Build Pipeline plugin expects 3 instances of this job to happen, only one happens and the others appeat as pending forever.Any ideas?
First image displaying what is happening
Second image displaying what is supposed to happen

Triggering a Jenkins job on a timer from a job run through polling

We currently poll svn and run a job if there are any changes. We then trigger a job if the initial job passes.
Additionally, I'd like to trigger a second job that only runs once a day. So if the initial job (job 1) runs 40 times, job 2 would also run 40 times, but job 3 would only run 1 time. (It can be decoupled as long as job 3 knows exactly what machine the last instance of job 1 ran on)
My initial thought was to use a plugin similar to Node stalker (https://wiki.jenkins-ci.org/display/JENKINS/Node+Stalker+Plugin) to just get the value of the node the previous run was on. The plugin doesn't appear to be working (it runs on whatever node as if the plugin does nothing).
Is there another way of doing this?
I am unaware of another way to do this in a similar manner to node stalker, however two other options come to mind.
The ugly:
If all the machines have a network drive they can access just keep a text file and when a machine completes job 1 and 2 successfully then it updates that text file with a unique identifier for that name, then Job three reads that file and it knows who ran jobs 1 and 2 last.
The less ugly:
This one depends on how long it takes to run jobs 1 and 2 (shorter is better, longer may not be feasible). Run a 4 job chain:
job3 launcher -> job 1 -> job 2 -> job 3.
This way you can track what machine is being used for job 1 and job 2 and pass those along as build variables into job 3.

Jenkins job wait for first successful build of other job

I have a Jenkins job that should not start building until another job has been built successfully at least once. They are not related per se, so I don't want to use triggers. Is there a way to do this?
Some background: I'm using SCM polling to trigger the second job. I've looked at the Files Found Trigger plugin, but that would keep on triggering the second job after the first on has been built. I've also found the Run Condition Plugin, but that seems to work only on build steps, not on the entire build.
Update - The second job copies artifacts from the first job. As long as the first job has never completed successfully, the Copy Artifact step fails. I am trying to prevent that failure, by not even attempting to build the second job until the first job has completed once.
One solution is to use the Build Flow plugin.
You can create a new flow job and use this DSL:
I've used 10 in the retry section but you can use any numbers.
This flow job can be triggered by monitoring the same SCM URL of your second job.
Update, here is a second solution.
You can use the HTTP Request plugin.
If you want to test that your first job has been built successfully at least once, you can test this URL:
http://your.jenkins.instance/job/your.job/lastSuccessfulBuild/
One example:
As my build has never been successful, the lastSuccessfulBuild URL doesn't exist. The HTTP Request changes my build status to failure.
Does it help?
The Block queued job plugin can be used for this: https://wiki.jenkins-ci.org/display/JENKINS/Block+queued+job+plugin

Jenkins - Triggering Scheduled Jobs

Is there a way to trigger a scheduled job?
I am building a pipeline of connected jobs which trigger each other once complete. I want one of the jobs to be scheduled to run at a particular time of the day. So I want to be able to essentially add to a queue to trigger at a later time.
Is that possible?
Cheers
To schedule a Jenkins job to run at a specific time, go to the job's landing page, click Configure from the left-side menu, scroll down to 'Build Triggers' section and pick 'Build Periodically'.
There you can specify the cron job formatted string to denote when and how often you'd like this first job to be scheduled for running.
If that job is not the first job in line, you can always use 'Quiet Period' option under 'Advanced Project Options' which puts in a delay in that job before the build steps actually run. You can specify the number of seconds you want that job to wait for before it actually executes.
This plugin seems to be piggybacking on the 'Quiet Period' feature though I haven't tried it myself: https://wiki.jenkins-ci.org/display/JENKINS/Schedule+Build+Plugin. You might have luck using it to your advantage.
You could use the Jenkins Workflow plugin suite (mentioned in your tag, perhaps unintentionally). It has a sleep step. If you wanted the next stage of the pipeline to run at a particular time of day, rather than after a fixed interval, you could do some simple computation with java.util.Calendar to determine the seconds between now and then.

Block upstream jenkins job while downstream is running

I know about the build blocker plugin but doesn't seem to work. Running Jenkins 1.609.
Job A triggers Job B.
I configured Job A to block if job B is running.
If you trigger A and while A is running you trigger A again, once the first A finishes, it triggers B. Then you get both A and B running which shouldn't happen. I guess that when the waiting A checks if B is running, it might be the case that Jenkins is in a middle state where it finished A but not yet really triggered B and therefore we get both of the jobs running.
How can I get this situation to work?
No need to use plugin. I have been using below solutions for a year.
Job Config --> Advanced Project Options --> Block build when upstream project is building
I would say it depends if you have a chain of jobs which need to be blocked.
I can suggest:
Build Blocker Plugin
Here you can set a regular expression to block certain jobs.
With:
.*PART_OF_YOUR_JOB_NAME*
You can block every job which matches this string

Resources