1 jenkins job trigger multiple jenkins jobs based on parameters - jenkins

Is there any Jenkins plugin that helps with the following:
if a directory <XXX*, is present in SVN folder <GoRoCo>
then the <GoRoCo>_<XXX> Jenkins job is called
?
Example:
In job "TEST" , I specify parameters like directory name (A, B , C) and folder name (G1R2) then job "TEST" should trigger the jobs "G1R2_A" , "G1R2_B" and "G1R2_C"

Use Parameterized Trigger Plugin. When specifying jobs to call in the plugin you can use tokens, as in JOB_${PARAM1}_${PARAM2}.

Take a look at that plugin, i think it does exactly what you are looking for:
https://wiki.jenkins-ci.org/display/JENKINS/Files+Found+Trigger

Use Build Flow plugin
With the help this plugin you can run as many jobs with or without parameter.

Use some scripts to create property file with the required parameters for each of the modified project and place them in the workspace directory.
Later you can use parameterised plugin to trigger downstream project like this.
Note: you might also have to delete those properties after triggering the down stream projects.

Related

Jenkins : Change the name of JenkinsFile

I'm using Pipeline Plugin under Jenkins
My job is basically using a file called "jenkinsFile" to get the divers steps to run.
-> My purpose is how to let the job use a different file name :
examples:
myJenkinsFile
build_JenkinsFile
deploy_JenkinsFile
buildSteps
...
Since it seems that "JenkinsFile" is a conventional format ,
is there any ways to change it if it's not verry clean ??
Suggestions ??
On the project section of the configuration page you just have to click Add > Pipeline Jenkins and then you can choose the custom name that jenkins will look for the pipeline.
If you want also a better level of customization you can also use Remote File Plugin, which allows you to put your pipeline in a repository and make it work with multiple repositories/branch (and of course you can still customize the name of the file)

Trigger Multibranch Job from another

I have a job in Jenkins and I need to trigger another one when it ends (if it ends right).
The second job is a multibranch, so I want to know if there's any way to, when triggering this job, pass the branch I want to. For example, if I start the first job in the branch develop, I need it to trigger the second one for the develop branch also.
Is there any way to achieve this?
Just think about the multibranch job being a folder containing the real jobs named after the available branches:
Using Pipeline Job
When using the pipeline build step you'll have to use something like:
build(job: 'JOB_NAME/BRANCH_NAME'). Of course you may use a variable to specify the branch name.
Using Freestyle Job
When triggering from a Freestyle job you most probably have to
Use the parameterized trigger plugin as the plain old downstream build plugin still has issues triggering pipeline jobs (at least the version we're using)
As job name use the same pattern as described above: JOB_NAME/BRANCH_NAME
Should be possible to use a job parameter to specify the branch name here. However I didn't give it a try, though.
Yes, you can call downstream job by adding post build step: Trigger/Call build on other projects(you may need to install "Parameterized Trigger Plugin"):
where in Parameters section you define vars for the downstream job associated with vars from current job.
Also multibranch_PARAM1 and *PARAM2 must be configured in the downstreamjob:
Sometimes you want to call one or more subordinate multibranch jobs and have them build all of their branches, not just one. A script can retrieve the branch names and build them.
Because the script calls the Jenkins API, it should be in a shared library to avoid sandbox restrictions. The script should clear non-serializable references before calling the build step.
Shared library script jenkins-lib/vars/mbhelper.groovy:
def callMultibranchJob(String name) {
def item = jenkins.model.Jenkins.get().getItemByFullName(name)
def jobNames = item.allJobs.collect {it.fullName}
item = null // CPS -- remove reference to non-serializable object
for (jobName in jobNames) {
build job: jobName
}
}
Pipeline:
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
library 'jenkins-lib'
mbhelper.callMultibranchJob 'multibranch-job-one'
mbhelper.callMultibranchJob 'multibranch-job-two'
}
}
}
}
}

Remove Jenkins builds by name

I have Jenkins job with parameters. Every build is named by number and name that is read from parameter (#1-build1, #2-example1, #3-build2, #4-example2). Is it possible to configure Jenkins to delete jobs by name and not by how old it is. In my example, if I issue new build named #5-example3, I want #2-example1 to be removed, and not #1-build1. Is there a plugin for removing builds by some filter?
Here is a Groovy Script that can do the job. But please replace the condition as per your logic.
Jenkins.instance.getItemByFullName('temp').builds.findAll { it.number.toString().contains '<your build name pattern to delete>' }.each { it.delete() }
Please add this as a build step in your job. This will simply do as you want. If need any help, please comment here. Hope this helps.

Jenkins Job DSL Plugin: How to Modify Parameters on other jobs

I want to create a job in Jenkins which modifies an existing parameter on another job.
I'm using the Job DSL Plugin. The code I'm using is:
job('jobname'){
using('jobname')
parameters {
choiceParam('PARAMETER1',['newValue1', 'newValue2'],'')
}
}
However, this only adds another parameter with the same name in the other job.
I'm trying the alternative to delete all parameters and start from scratch, but I haven't found the way to do that using Job DSL (not even with the Configure block).
Another alternative would be to define the other job completely and start from scratch, but that would make the job too complicated, specially if I want to apply this change to many jobs at a time.
¿Is there a way to edit or delete lines on the config.xml file using the Job DSL plugin?

Making Jenkins job to choose either of the two repositories through a parameter

I have 2 Jobs which checks out the code from 2 different repository ( A and B resp ).
How can I have a single job which checks out the code from either A or B depending on the parameter so that i want to reduce the number of jobs in jenkins.I tried the sub version release plugin,but this did not perform what is required by me
Thanks in Advance
Why don't you write a script and run it. use parameterized build and configure the parameter. then based on that parameter, clone the repository with the use of script

Resources