Jenkins plugin for collecting user input - jenkins

I am creating a Jenkins Pipeline job.
I want to achieve this: in the job home page, I want an HTML input tag, before each time manually triggering the build, I first fill in something in the tag, then the value can be retrieved and used in the pipeline script during the build.
It there a plugin for this purpose?
Thanks.

This is a so-called Parameterized Build.
In your pipeline definition, you can add these build parameters using the properties step, which comes with the workflow-multibranch plugin.
A simple example would be as follows:
properties([
parameters([
string(name: 'DEPLOY_ENV', defaultValue: 'TESTING', description: 'The target environment', )
])
])
P.S: As this feature is quite hidden, I wrote a blog post about this a few weeks ago.

Related

post build action with parameters

I have 2 parameterized pipeline A and B.
project A execute project B as a post build action.
Im using "Predefine parameters" to pass parameters to project B, but seems project B using default values and not the provided one.
the pass parameter is project A parameter.
Jenkins can get weird around parameters. If you are using a declarative pipeline, then define the parameters within the code instead of using the option on the Jenkins page:
build([
job : 'B',
wait : false,
parameters: [
string(name: 'process_id', value: "${id}")
]
])
And in pipeline B:
parameters {
string(defaultValue: null, description: 'parameter', name: 'process_id')
}
If using freestyle jobs, the way you have defined the parameter is correct. If Jenkins is not using the correct parameter and instead is using some cached value, then try these steps:
Clone your downstream job
Rename you downstream job to something else
Rename the cloned downstream job to the correct name that should be used
Run the downstream job once
If the problem is that Jenkins caches the parameters used, this should fix it.

Add Jenkins job parameter to all jobs

All of my Jenkins jobs need the same two parameters added to them. I have way too many jobs to configure by hand in a reasonable amount of time.
Is there a way to add a job parameter to them all at once? Even one folder at a time would save me a great deal of effort. Currently, hacking the config.xml files seems faster than adding them one by one via the UI.
Again, these parameters do not exist yet, so unless Configuration Slicing has some hidden feature, I am not sure how to accomplish this.
TIA for any answers!
I can think of following possibilities.
For declarative pipelines the parameters directive could be added into the pipeline scripts.
parameters {
string(name: 'FIRST_ PARAM', defaultValue: 'Test')
string(name: 'SECOND_PARAM', defaultValue: 'Test2')
}
If the jobs are scripted pipelines you could add
properties(
[
parameters(
[string(defaultValue: 'Test', name: 'FIRST_PARAM'),
string(defaultValue: 'Test2', name: 'SECOND_PARAM')]
)
]
)
The jobs need to be built once in order for parameters to be visible.
Another possibility would be to iterate over all jobs and add parameters
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>FIRST_PARAM</name>
<description></description>
<defaultValue>Test</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
to properties tag in config.xml of the jobs.

Passing extended choice parameter value from one job to another remote job in Jenkins pipeline

I am working on a scripted Jenkins pipeline, and I am using the triggerRemoteJob plugin to trigger a remote job on another Jenkins instance.
The remote job has an extended choice parameter.
The syntax for passing parameters to the triggerRemoteJob plugin seems to differ from the build Job plugin.
What is the correct syntax to pass the value of an extended choice parameter while using the triggerRemoteJob plugin?
EDIT
Posted an answer below.
If there is a way to solve the issue in Jenkins pipeline, please post it as an answer.
As far as I know, there is no special class for those parameters. I've always used the String one and it works as long as you introduced a valid option:
string(name: 'PARAM', value: "option"),
--- EDIT ----
I do it with this syntax:
build(job: 'my_job', parameters: [
string(name: 'PARAMETER', value: 'value'),
])
Referring to this issue thread in github:
https://github.com/jenkinsci/coordinator-plugin/issues/46
It seems that because the Extended choice parameter does not support an interface in jenkins, calling the triggerRemoteJob with an ext. choice parameter is not supported.

This build is parameterized option missing in Jenkins

I'm trying to get a parameterized build running with Jenkins. All the tutorials point to a This build is parameterized check box like here. Other tutorials point to this documentation but after searching around I can't figure out how to get the check box to actually show up. Am I missing something?
Edit: Figured it out - the This build is parameterized check box was there all along under a different header. The Office 365 Connector plugin creates a new header that splits the general options in half. I thought that the check box was being used specifically for that plugin, but the header was just misleading.
If you looking for "This project is parameterised" option that is a native Jenkins functionality. You don't need any plugin for that. It should be under the General tab.
see my plugins list; I have not installed any plugin.
In Jenkins 2.330 (without related plugins) we see no option like This build is parameterized or This project is parameterized at repo level.
Jenkins does draw a Build with parameters button for us instead of the usual Build button, provided the Jenkinsfile declares some parameters.
At branch level, View Configuration button then shows a greyed out, enabled checkbox This project is parameterized (it is not greyed out in repos where the Jenkinsfile declares no parameters, but we opted to configure things at above-repo level so it is not clickable)
Example Jenkinsfile:
#!groovy
properties([
parameters([
booleanParam(name: 'destroy', defaultValue: false,
description: 'delete images', )
])
])
node('normal') {
if (this.env.destroy == 'true') {
sh 'echo DESTROY MODE'
} else {
sh 'echo DRY RUN'
}
}
Might have to click Scan Multibranch Pipeline Now after adding those parameters:

Dynamic Parameter in Jenkinsfile?

How can I use the Jenkins Dynamic Plugin in a Jenkinsfile?
What I am looking for is a Jenkinsfile snippet that:
Enables the Build with Parameters option in the Jenkins job
When selected, a script that populates a list that can be used Dynamic Choice Parameters is populated and the user will see a drop down list.
When trying:
Pipeline syntax in the Jenkins editor
Selecting properties: Set job properties as Sample step
Selecting This project is parameterized
Using Dynamic Choice Parameter
Enter values for Name, Choice Script, Remote Script etc
Generate Pipeline Script
I get the following template:
properties([
parameters([
<object of type com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition>
]),
pipelineTriggers([])
])
i.e. the generated pipeline script does not contain the data that I have entered in step 5. above. How can I modify parameters so that parameter name, choices, etc will be visible to the user?
Jenkins version: 2.19.3
Dynamic Parameter Plugin version: 0.2.0
there is no need anymore for the Jenkins Dynamic Plugin anymore. Just use the normal choice or string parameter and have the value(s) updated by groovy code.
#!/bin/groovy
def envs = loadEnvs();
properties([
parameters([
choice(choices: envs, description: 'Please select an environment', name: 'Env')
])
])
node {
try {
stage('Preparation'){
...
If you use the choice parameter be aware the you must provide a string where the values are separated by a new line.
For example:
"a\nb\nc"
If you really need to plugin, then vote on this issue JENKINS-42149.

Resources