when to use trigger builds remotely in jenkins - 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.

Related

bitbucket plugin in jenkins pipeline should have several repositories as trigger

We use several git repositories of sources for common builds. Because not only one, but several of them might be changed alone, we would need several repositories to be checked to trigger invocation of a jenkins pipeline script.
I guess, that others might also be interested in this kind of extended functionality. Any proposal/hint how to resolve this is highly appreciated.
We have not implemented yet the bitbucket plugin use, because this would be to incomplete to serve our needs now.
You could try using web hooks
Put your web hook at project level, and changes to repositories within the project will trigger the web hook.
Then on the Jenkins side you will need the Generic Webhook Plugin
Bitbucket sends a json payload to Jenkins which consumes the payload.
You can use the Json path expression tester to get relevant fields from the payload. From that you can decide what build should be triggered.
The newer way of doing this is to use the Bitbucket Server plugin for Jenkins

Trigger a downstream project on demand

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:

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.

Can I force a plugin in Jenkins to run every single time any job runs

I have a plugin in Jenkins for Checkmarx which scans the source code for static code analysis. Is there to make that plugin be compulsory for every job in jenkins?
For that matter any plugin.
The answer, that you probably don't want to hear, is: No.
The only way you can enforce something to happen at all times, is by writing your own plugin for your own "Project type" (instead of Maven or Free-style), and then enforce that everyone uses your project type.
Found a implicit way to do it.
Using jenkins rest api(batch,python,ruby) - run through all job
config.xml.
Download the jobConfig.xml
Update the xml with the plugin(checkmarx in this case) config
Upload(POST) it back to jenkins server.
Run this on a schedule and it shall force everyone to use it.
As I said its an implicit way of doing it.
Checkmarx plugin provides a build step, so it will run every time the job runs. No need to force, if I understand the question correctly. Just make sure the "Skip scan if triggered by SCM Changes" flag is unchecked, which is the default. See more info about the plugin here: https://checkmarx.atlassian.net/wiki/display/KC/Configuring+a+Scan+Action
Downloading the config.xml for the job and posting it back is a bad idea for several reasons. First checkmarx does not require the code to be compiled so you are wasting precious cycles on a build slave. Second Jenkins jobs can do more than compile and they could deploy to production accidentally. Just don't do it. The best way to do what you want to do is to download the config.xml file and then extract the repository url. You can use the Checkmarx rest api to perform a scan. You can probably name the program in checkmarx in some way to relate it back to the jenkins job.

Resources