Trigger a downstream project on demand - jenkins

Given the following situation
main-job builds and tests a project
installer-job copies artifacts from main-job, and packages them into an installer
installer-job is set as downstream project of main-job via Parameterized Trigger Plugin.
But the installer-job should only be triggered on-demand from main-job's build page.
It's possible to trigger the downstream job on the project page:
But it doesn't seem possible to trigger the build from a specific build page.
Is there any option to get such a trigger button on the build page?
Note: It's a freestyle project, not a pipeline one. So things like the Build Pipeline plugin don't help, unfortunately.

An elegant solution is possible via the Promoted Builds Plugin. "Promotion" is some activity that's performed when a build fulfills certain criteria, like
build was successful
all downstream builds passed
explicit, interactive confirmation
In your case, this condition will be simple: just "main-job" needs be successful, and you will want to confirm explicitly.
There's lots of possible steps that can be triggered as promotion activity -- what you want is to trigger a build of the "installer-job", which can be configured easily.
To summarize, for "main-job", you will configure something like this:
When you do that, the 'main-job" builds will feature a "Promotion Status" button. After pressing the "Approve" button there, the promotion will be enabled and the "install-job" will start building:

Related

Disable automatic trigger build jenkins multibranch

I have a multibranch project in jenkins, and every time I press Scan Repository Now it queue a new build just because
‘Jenkinsfile’ found
Met criteria
What I'd like to do is whenever I scan the repository, it only add Pull Request to the project without triggering a build. And also, if I turn on scan repository trigger, periodically if not otherwise run, every time it branch indexing, it also build the pull request even after I turn on Skip initial build on first branch indexing.
What I'd like to do is whenever there's a comment 'build' in the pull request, then it builds the branch, so if the pr doesn't contain the comment, it should not build anything.
How can I achieve this?
This is my setup
I use Jenkins 2.180
According to the pipeline documentation there should be a option do dissable Index Triggers on Multibranch types, see https://jenkins.io/doc/book/pipeline/syntax/#options
But i didn't find the option itself either, so i deactivated it per Pipeline definition in the Jenkinsfile of every branch :/
overrideIndexTriggers
Allows overriding default treatment of branch indexing triggers. If branch indexing triggers are disabled at the multibranch or
organization label, options { overrideIndexTriggers(true) } will
enable them for this job only. Otherwise, options {
overrideIndexTriggers(false) } will disable branch indexing triggers
for this job only.
I also use SCM webhooks to autmatically trigger the branch indexing etc
The default for Build Strategies is to OR the list together. You'll need to remove the existing build strategies and add an "All Strategies Match" build strategy and add "Change Requests" and "Skip Initial Build on First Branch Indexing" to that.
Source: https://issues.jenkins-ci.org/browse/JENKINS-58442

Jenkins executing one job that runs multiple jobs

i am new to Jenkins , i need to execute one job that run's another multiple jobs in parallel were it should not stop even if one job fails.
i am not sure how to achieve it. After googling i can achieve by 3 ways Multi-Job plugin , Pipeline multiple Jenkins jobs , Build after other projects , Build Flow Plugin.
can any body please provide me the correct way.
Update : i am trying to achieve this using the pipeline plugin , can any body suggest me were it was correct choice ?..Please suggest!..
We use the Parameterized Trigger Plugin to do this.
In your build configuration add a Trigger/call builds on other projects build step. Add the names of the builds you want to trigger as a comma separated list and make sure that the Block until triggered projects finish their builds box is unchecked. Your build will trigger each of the listed builds, however note that your parent build won't wait for them to finish it will just trigger them and then perform the rest of it's buildsteps so if you have buildsteps.
If you do want to wait then check the block until triggered builds finish box, but set the options for when to fail the build, build step or mark the build as unstable appropriately.
If you need to pass parameters to the jobs you can add parameters using this plugin. If your downstream jobs need different parameters for different jobs you can click the add trigger button which adds another project to build where you can specify different options.
If these other jobs are follow up jobs to the current job and you don't need to wait for them to finish you can also achieve what you want to do by using the post build action build other projects, but again this occurs after the current job and you won't be able to use the results.
can any body please provide me the correct way.
I wouldn't approach using Jenkins with a "one correct way" mentality. Often times the requirements of your build will dictate which method or plugin you use in your build configurations.
The job can start other jobs via the jenkins api.
updated Answer : i used pipeline plugin to achieve my task and tuffwer was right to if u have paramaterized trigger plugin!..

Run Jenkins job all the time

I've a Jenkins job I want to keep running all the time. When a build is ending, I want to immediately trigger another build. How can I do that?
Thanks, Omer
There are two different job configurations for that:
Build Triggers -> Build after other projects are built
Add a post-build action Build other projects
In both cases, you can enter your own Project, so it'll be triggered again every time a build is completed. You can also specify if this should be done only while the project is stable.
There is however one (probably more) drawback in this approach, which is that it'll create enormous overview pages, where all build triggers are listed:
So i'd recommend to do something else and for example use the Jenkins API to trigger a new build. There are many ways to do that, one simple example is adding a build step Execute shell and do something like:
curl -X POST http://localhost:8080/job/$JOB_NAME/build
If you have configured the Jenkins URL, you could also use $JOB_URL. You can also add post parameters to trigger a parameterized build.

when to use trigger builds remotely in jenkins

I have searched many links but could not find the appropriate answer. I need to know when should I use "trigger builds remotely". I have gone through Integration Jenkins with SVN, there I saw that I need to check this option. I am not getting any idea regarding this.
This is used when someone commits to the source control (SVN) it shall ping Jenkins to trigger a build.
The "trigger builds remotely" option is used when you want to trigger a build from another tool:
As explain, you can trigger a job using the Jenkins URL:
http://your-jenkins-url/jobs/your-job/build
You can secure this URL by using an authentication token.
I hope it helps :)
You don't have to use it. There are multiple ways a build can be triggered
Build periodically - based on repeating cron schedule.
Poll SCM - based on SCM commits. This is also required when building on SCM hooks.
Build after/before other projects / Various - multiple ways to setup cross-project dependencies for selecting when to build.
Trigger builds remotely - to delegate the logic for monitoring/triggering builds to 3rd party applications/scripts.
The last one is used when you don't want Jenkins to be doing the triggering of the jobs (but Jenkins will still do the execution). It allows you to trigger a build through a specific URL. To avoid unauthorized triggering (since there is no login at this point), an authentication token can be provided.
This URL can be invoked any way you want: manually, command-line script, or some other 3rd-party application.

Jenkins, Do not trigger "post build actions:trigger parameterized build" when built manually

I have a job that, when complete, starts another job through post-build actions:trigger parametrized build. However at times, I wish to just run one specific job manually (not through the timer) without chaining off the rest of the jobs. How would I accomplish such a task.
Thanks in advance!
You can't in your current setup.
You want the Flexible Publish Action to make your post-build action conditional (probably based on parsing the console log for indication that the build is manual)

Resources