jenkins: promote before job ends - jenkins

I'm trying to configure a job in jenkins in a way that the promotion process (Promoted builds plugin) happens in the middle of a run. The point is that there are some annoying tasks like javadocs, sonar integration,... that can be run even after the promotion process, therefore I would like to make the build, run all needed tests and then promote the build automatically. Other tasks can run after the promotion process.
Do you know how I can implement this using the Promoted builds plugin?
Thanks in advance for the help.

No, Promotions only run on completed builds. If you want to run it in the middle of the job, then it's a build step, not a promotion.
You can either configure build steps for your actions (same actions as promotions). You can even call other jobs, and wait for them to complete (or not wait).
Or you can configure your "after promotion" tasks as a second promotion that is executed after the first one.

Related

Run jenkins job without triggering downstream jobs

I have a jenkins job with a couple of downstream jobs which are triggered upon the job finishing correctly.
There are times when I want to run the initial job without triggering the downstream jobs. Is this possible?
It sounds like the conditional build step plugin might be of help. You can configure it to trigger other jobs based on various conditions, like so:
Here, the conditional build step has been configured to run downstream-job if foo.txt exists in the current workspace.

Jenkins, Multijob, how to run in parallel?

We have set up a Jenkins instance as a remote testing resource for our developers. Every time a tag is created matching our refspec a job is triggered and the results emailed to the developer.
A job is defined as follows:
1 phase consisting of three jobs (frontend tests, integration tests,
unit tests)
All subjobs are executed, irrespective of success
Email the developer the test results
This setup mostly works except for two issues:
I cannot get the job to run in parallel. The subjobs run in
parallel, but only one instance of the job runs at a time. Is this
something I can configure differently somewhere, or is this inherent
in the way the plugin works?
The main job checks out and occupies one of our build servers for
the duration of the job. Is there a way to do git polling and then
just grab the hashref and release the build server on which the
polling was done before continuing building the subjobs?
In the multi job plugin, everything runs in parallel that is listed in the same "Phase", however the multijob itself needs somewhere to run. If you have a build followed by a test phase, you can add a "Build Phase" prior to the test phase, and only that phase will require a "build server".
There is an option called "Execute concurrent builds if necessary" that will allow multiple jobs of the same name to run simultaneously. This option must be set for the parent job and the subjobs as the default behavior of Jenkins is to only allow one build of a Project (job) to run at a time. Beware: Read the comments as this may have unintended side effects.
Not clear what you mean about polling however if using git, you may want to use webhooks so that pushes to the git repository directly invoke Jenkins. No need to poll.

How do I run a task on failure in Jenkins?

I've got a Jenkins job that is intended to do the following:
Build a project and deploy it to a test server
Run tests
If the tests fail, roll back the server to the previous version
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?
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.
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

Jenkins: Killing downstream jobs and then restart

So I have a Jenkins Job which kicks off other jobs to run test scripts in a particular environment after code has been pushed to that environment (Example: Code is pushed to QA, Test Project is built, and then all QA tests run using "10 separate" test jobs).
This works great for the most part, however, there are times when I get "too many tests running" because people will perform lots of builds to a particular environment and that means I have multiple versions of the same tests running.
I would like to make it such that when a job runs and finishes, if its down stream jobs are currently running, they are stopped and then started again (I want the tests to run on the most recent build instead of having 2 test jobs being run on 2 different builds).
Does anyone know of a good way to do this? Or is there a plugin someone can recommend?
What I can recommend is that you add a batch file containing a HTTP request to cancel the last build of the job in question and then trigger the job in the next step. I think the URL below should help.
So in PostBuild step of JOB-A add a condition(single-and) step to check if the JOB-A successeded then
Execute a batch command to CANCEL JOB-B
AND
Kick off JOB-B again
Thsi should do the trick. (replace the HUDSON_URL)
HUDSON_URL/job/JOBNAME/lastBuild/stop
obviously if you may need to consider authentications if Jenkins requires a login.
Also i would say maybe in JOB-B you might want to set to block if upsteam project is building so it waits for the upstream job if its not running yet.
another reference here:
Hope this helped.

Jenkins: multiple jobs with one shared resource

So I have a dynamic number of jobs which all have only one build step.
at some ("random") point of its execution, each job run some application which couldn't have more than one instance at a given time.
In general I do want parallel run of the jobs. but I still need some synchronization when two or more jobs trying to run the above application at the same time.
I though about using the Locks and Latches plugin , but I can't see how this will help me in my situation.
Ideas will be more than welcomed!
Run the application from a separate job (let's call it APP_JOB) that you would invoke via Parametrized Trigger Plugin (as a build step, not as a post-build step) from your other jobs, with an option to wait for it enabled. By default Jenkins won't run parallel instances of APP_JOB.

Resources