How to create Jenkins parameter job using code - jenkins

I want to create this parameterized job in Jenkins using code. Can somebody point me or give me hint to make it possible.

Related

Jenkins Pipeline: how to trigger a build as a downstream that requires an input

I have a Jenkins pipeline job defined. The Jenkinsfile of this job has an input defined using a dropdown. So when the build is triggered the user is requested to select an input.
For manually triggering this is working great!
However, if we want the same job to be triggered by another job as a downstream. How can we do this? providing the input parameters.
Thanks
As #StephenKing pointed out to get setup we need, we have to move away from using input step and make the build parameterized.
The answer I was looking for is here

Trigger Jenkins build cli, nested jobs

I'm struggling with a bit of trouble here. I'm supposed to trigger Jenkins build via Jenkins CLI. While it should be easy in itself, it is not. The trouble is that, my jobs look like following
A-
|
B-
|
C
So they are nested. When I give command list all I only receive A as an output. So I can only trigger job A but my task is to trigger job C. How can I do it?
I've tried passing the link of C job as a parameter in Jenkins CLI but it didn't help.
Figured it out, maybe it will help somebody later on. Instead of passing job as 'a/job/b/job/c' we're supposed to pass it as 'a/b/c'.

Jenkins to trigger another build/project dynamically

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

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