How can I set up my Jenkinsfile so that some params only appear if another param is selected? - jenkins

I am working on a multibranch pipeline so all of the parameters are defined inside the Jenkinsfile. I'd like to know if there is a way that I can set it up so that if I am inside "Build with Parameters", and I click on a checkbox that I have defined in the Jenkinsfile, more parameters appear as options.
I just want to reduce clutter and confusion when someone wants to build my pipeline. I have so many parameters and a lot of them are unnecessary unless one checkbox is clicked.
If this isn't possible, I'd love any other suggestions to make my parameters section more organized.
Thanks!

For your case, you can use Active Choices Plugin available to download from Manage Jenkins >> Manage Plugins.
In the documentation page of this plugin, you can find various examples which will you to understand and setup.

Related

How to receive inputs from UI to jenkins

I want my jenkins job to take inputs from the UI and pass them as parameters while building . parameters can be url or files or both. Is this possible in jenkins? If yes, can someone help me how this can be done?
You can define parameters by selecting "This build is parameterized" in your job configuration. There are several parameter types built-in and several plugins will provide additional types.
See https://wiki.jenkins.io/display/JENKINS/Parameterized+Build.

Is there a way to use parameters in Jenkins job description field?

I have a job creator job that creates other jobs in jenkins and I would like to use the created jobs name in the description.
For example for name "JobXX" i would like to have:
"This is documentation for JobXX etc.."
In "Execute shell" build step I can refer to the jobs name via $JOB_NAME parameter but that does not seem to work in the description field.
Any ideas on how to do this? Or if it's even possible?
Never used it, but take a look to the Project Description Setter Plugin:
https://wiki.jenkins.io/display/JENKINS/Project+Description+Setter+Plugin
In this blog it explains better how to use it:
http://www.tothenew.com/blog/setting-dynamic-project-description-and-build-description-in-jenkins/
Among the different variables you can use there is {PROJECT_NAME} which fits your needs.
Besides this, this plugin allows you also to automatically set descriptions to each specific build.

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

Taking out common config of jenkins jobs

I have about 200 jenkins, each of them has a long config page but actually most config are the same. Everytime when I need to update something in the common config, I write a groovy script to loop though those jobs and update them one by one. It's a pain because it takes about 5 minutes to update those jobs by the groovy script. I am wondering is there a jenkins plugin(or something else) that I can use to put the common config in one place? jenkins slicing plugin doesn't work well, I think it conflicts with another plugin.
Thanks
Sounds like a job for the job-dsl plugin
From the wiki page
The Jenkins job-dsl-plugin attempts to solve this problem by allowing
jobs to be defined with the absolute minimum necessary in a
programmatic form, with the help of templates that are synced with the
generated jobs. The goal is for your project to be able to define all
the jobs they want to be related to their project, declaring their
intent for the jobs, leaving the common stuff up to a template that
were defined earlier or hidden behind the DSL.

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