Jenkins to trigger another build/project dynamically - jenkins

Is there a way in Jenkins to trigger another build/project dynamically based on a parameter value in parent project?
The reason for this is that I have 100's of projects and I don't want to use pipeline/conditional post build plugins to link all jobs.
I know of a way using REST API but trying to find is there a way to trigger a single project from those 100?

Easy with Pipeline Plugin. Just define your parameter (say MY_DOWNSTREAM_JOB) and use it inside the groovy script definition:
build MY_DOWNSTREAM_JOB

Related

Jira post action script to get custom values

I have a Jira issue that has different custom fields. I want to trigger a parameterized Jenkins job, after the Jira issue is filled up and moved from Open to In Progress, and the Jenkins job parameters will be each of the field values the Jira issue contains.
I was trying to do this with two approaches:
- Jira Trigger plugin, but I can't find the way to get the Jira issue custom fields values and neither to use them as parameters to trigger Jenkins job.
- Using the post action script on the Jira issue transition, but I'm struggling to know how to get the Jira custom values on the script, to then be used to POST them to Jenkins job
You can use Script Runner plugin for this requirement .
https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira
This plugin can be used as a listener/post (groovy code) to the desired state transition which will capture the required field values and feed them to Jenkins through API call .

How to configure parameters with time stamp

I have a job ( parameterized build) I am using BUILD_ID as a parameter and I need to add time stamp for the every BUILD_ID.
How to add time-stamp to the parameter.
I need the BUILD_ID value like Test_Build_{time-stamp}.
Kindly help me
There are numerous ways to do this.
Probably your best bet is the Dynamic Parameter Plugin. On the plugin page, one of its main examples does almost exactly what you described.
The Active Choices Plugin allows you to run groovy code to generate your parameter value(s). Here's a screenshot of the plugin setup along with the groovy code:
The EnvInject Plugin allows you to insert environment variables from a properties file as a build step. Using this method you would basically have to have 2 build steps, one to create the properties file and another to read it.
Or using the Groovy Plugin, you can add a groovy script build step to modify the parameter value.
I'm sure there a number of other ways to accomplish this as well.
Install Zen Timestamp plugin and use variable $BUILD_TIMESTAMP

Jenkins same parameters on multiple jobs

we have many Jenkins Test Jobs dependening on one library. Every Job has multiple parameters (always identical).
Now the problem is that if we change or add an parameter in the library, we have to touch every single jenkins job configuration.
Is there a way to configure the parameters of multiple jobs in a central place? Like defining the parameters in a file and refering to that? or is there jenkins plugin for that use case?
Thanks,
Marco
You can edit parameters (and much more) of multiple jobs in one place with Configuration Slicing Plugin:
Job Parameters (aka "This build is parameterized") can be configured across multiple jobs at one time through the "Parameters" link. To indicate which parameter you are configuring, note the "JobName[ParameterName]" syntax.
Not sure if this can help if you use some advanced parameters like File parameter, Dynamic parameter etc.
Use Build Flow plugin
You can run same or multiple jobs many times with different configuration.
Use Multijob Plugin and parameterized plugin
You can pass different parameter by using these plugins

Generic jenkins jobs

I wonder, if it is possible to create generic parametric jobs ready to copy where the only post copy action is to redefine its parameters.
During my investigation I find out that:
- I can use parameters in svn path definition
- I can define the flow of builds using *Build Flow Plugin*
However I cannot force Jenkins to use parameters inside job names definition for promotion process. Is any way to achieve that?
Since I create sometimes branches from master I would like to copy the whole configuration of jobs but only one difference most times is that in the job name definition I replace master with branch name.
Why it not possible to use a parameter as the branch name?
Then when you start to build the job, you can input the parameters based on the branch you want to build.
Or find some way to get the branch info and inject it.
For example, we have one common job, which will monitor maybe 20 projects, if any of those job was merged into git, our gerrit trigger plugin will start to work, and all of job name, and branch is got dynamically from parameters.
Hope this works for you.

Adding a parameterized parameter to a jenkins job

I need to add a same boolean parameter ( from "Add Parameter" drop-down menu) to 100 existing jobs.
What is a better way to do it?
Thanks
This is a job for Jenkins job-dsl https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin
This exposes the job structure to an API which can be used to modify the configuration. This is run as a separate Jenkins build step in a job
There is also a somewhat unwieldy, yet oftentimes-handy, plugin called Configuration Slicing. I've found it useful sometimes, in this situation.
Use Build Flow plugin. It allows to write DSL scripts.
example:
build("job-name", parameter:"vlaue1")
build("job-name", parameter:"vlaue2")
you can pass as many values like this.

Resources