Jenkins: How can I populate parameters from database to parameterized job? - jenkins

I need to pull values from database and show parameters as dropdown in Jenkins parameterized job. Is there any available plugin to achieve this?
Help would be appreciated :)

We have to use Jenkins Dynamic Parameter Plug-in to pull values from database and show parameters as dropdown in Jenkins parameterized job.
LINK:
https://wiki.jenkins.io/display/JENKINS/Dynamic+Parameter+Plug-in
We have to write groovy script to pull values from database and click on above link for more details.

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 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

Get the job link in groovy script

We need to update few job configurations accross all jobs and there are several instances of Jenkins running for multiple projects. We need to udpate SCM database path and the SCM password.
I am able to do the database path, but for password there is no set method. So to overcome this, I am just trying to print the link of the job for which we need to update the password. I could not find an API for job link.
Could you please help me out here, or suggest a better solution to update the password?
import hudson.model.*
jenkins = Hudson.instance
for (item in jenkins.items){
println jenkins.getRootUrl()+item.getUrl()
}
Tried this in script console. Lists all jobs absolute URLs. You just need to add the logic to get your jobs list

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