This build is parameterized option missing in Jenkins - 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:

Related

Using a Jenkins pipeline multiline /multi-line string parameter

I'm converting a bunch of jobs to use the Jenkins pipeline language.
In plain/normal Jenkins we can use parameter types including:
string
boolean
choice, and also
multi-line string.
A parameter using one of these types will pop up and prompt the user for input when they run the Jenkins job.
The available parameter types for Jenkins pipeline are: (According to here).
booleanParam
choice
file
text
password
run
string
There is no multiline string input parameter listed for pipeline. The Jenkins documentation say the documentation is "young" and still incomplete.
Has anyone managed to get a multi-line string input parameter working with the Jenkins pipeline?
Multi-line string parameters are in the out-of-the-box Jenkins package, but doesn't seem to be there in the pipeline.
I discovered the solution by looking at the Jenkins source code:
parameters{ text(name: 'mytextparam',
defaultValue: 'Default lines for the parameter',
description: 'A description of this param')
}
This pops up a multi-line text input prompt which becomes the parameter value which you can refer to later as params.mytextparam
This is not documented in the Jenkins Pipeline documentation, so there might be issues like it being unsupported or withdrawn in a future release. Or it could go the other way and they might document it in the next release.
There is a plugin that called:
"pipeline-syntax"
You should use it if you need some stuff for Jenkins pipeline.
1.Install the plugin: I installed it from "plugins" in my Jenkins server under "Manage Jenkins" then, Plugin Manager. source:https://wiki.jenkins.io/display/JENKINS/Pipeline+Plugin
2.You will see the plugin in the main screen of Jenkins on the left side. select it.
3.On the plugin select whatever you want for the plugin. here is an example of what you need now, check this out:
Go To Pipeline syntax dialog (/pipeline-syntax)
Select properties: Set Job Properties
6.After that press on "GENERATE PIPELINE SCRIPT".
7.copy the code (or part of it that you need) and add it to your Jenkins pipeline..
Let me know if this was helpful
Multi-line string parameters are text parameters in pipeline syntax. They are described on the Jenkins Pipeline Syntax page.
Example:
parameters { text(name: 'DEPLOY_TEXT', defaultValue: 'One\nTwo\nThree\n', description: '') }

Adding custom job property to Jenkins job

I want to add a new mandatory job property to capture the some custom fields in the jenkins job. I searched in the plugins list but couldn't find any relevant plugin that solves the issue. Is there any plugin to solve this ? (Note: Extra columns plugin doesn't solve my usecase)
A freestyle job can be configured to build with parameters. See: https://wiki.jenkins.io/display/JENKINS/Parameterized+Build
You can configure the parameter type (string, boolean, drop down etc), give a description of the parameter and a default value. The string parameters can include validation rules:
https://wiki.jenkins.io/display/JENKINS/Validating+String+Parameter+Plugin
Though this only warns when the current parameter value does not meet the regex validation rule, it doesn't prevent the build from being submitted. If submitted in this state, however, the build will fail.
From a quick google, it appears this doesn't work for pipeline jobs, See the last comment on the plugin page url above from Miguelángel Fernández:
If you look at the implementation of class ValidatingStringParameterValue you'll see that it overrides the implementation of public BuildWrapper createBuildWrapper(AbstractBuild build) in a way that aborts if the string is invalid. This will only work on Freestyle jobs and other job types extending AbstractBuild. I'm afraid this does not apply to pipeline jobs. Maybe in your prior project you used freestyle jobs.
An alternative for freestyle jobs is to do in job validation before initiating any build steps using the 'Prepare an environment for the run' from:
https://wiki.jenkins.io/display/JENKINS/EnvInject+Plugin
You would need to write groovy to check the parameters submitted and abort the build at this point if the values aren't suitable. Something like:
def validateString = binding.variables.get('testParam')
if (!binding.variables.get('testParam').matches('\\d+')) {
println "failure of parameter validation - does not match regex"
throw new InterruptedException()
} else {
println "Validation passed carry on with build"
}
This doesn't work on pipeline builds - as the plugin is quote:
'This plugin has some known limitations. For Example, Pipeline Plugin is not fully supported.'.
But if you are using scripted pipelines you can implement something similar:
stage 'start up'
if(!env.testParam.matches('\\d+')) {
error 'failure of parameter validation - does not match regex'
}

Jenkins plugin for collecting user input

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.

Allow users to pick Green Jenkins builds to deploy

I want to allow testers/BAT users/Ops etc to have a list of builds to pick from that they can deploy to a list of environments. The list should only contain builds that have passed all the way through our automated Jenkins Pipeline and the environment list will be a pre defined list. They should be able to pick from old and new builds. The deployment job is all setup. I was looking at writing a simple web page interface that hooks into Jenkins via the JSON API but if there is any way of doing this via Jenkins then that would be great.
You can do this:
CI build store successful artifacts in artifact repository (i.e: Artifactory)
Build has a parameter called "BuildToDeploy" or similar. That build parameter is created with Dynamic Parameter Plugin so it gets populated with list of builds from Artifactory.
Testers choose a build from a list of green artifacts.
In order to achieve step 2 as "Default value Script" of parameter you add some Groovy code that gets the artifact list from artifact repository. In Artifactory it would be something like jfrog rt list CIBuildArtifacts
Interestingly enough with Jenkins declarative pipeline you can do that in a very simple OOTB way. Although you have to twist the idea a bit.
In general for any pipeline that you would like to be able to promote you could have an extra stage using input, submitter
An optional comma-separated list of users or external group names who are allowed to submit this input. Defaults to allowing any user.
and parameters.
pipeline {
agent any
stages {
stage('Example') {
input {
message "Should we continue?"
ok "Yes, we should."
submitter "alice,bob"
parameters {
choice(name: 'DEPLOYMENT_ENV', choices: ['one', 'two', 'three'], description: 'where to deploy?')
}
}
steps {
echo "Hello, ${PERSON}, nice to meet you."
}
}
}
}

How to display info directly on build page in Jenkins?

I would like to have the following workflow in Jenkins:
user clicks 'Build Now'
user fills out build parameters
user clicks 'Build'
information is generated (via a script) and presented to user along with 'Continue' button
user clicks 'Continue' button which simply triggers another job
How can this be done?
in Jenkins Pipeline method use as
script{
currentBuild.displayName = Build_Display (this will be overwrite the Job number)
currentBuild.description = Build_description
}
Alternatively to solution with groovy script plugin, you may generate information together with button with REST command using Rich Text Publisher Plugin - you just don't have to write groovy script, only markup.
It adds a custom html markup to build page after build had been executed.
It allows to configure a message using file, or environment variables.
Use the Execute shell action to create a shell script that sets an environment variable. For example: echo "BUILD_DESCRIPTION=example" >BUILD_DESCRIPTION.setting.
Use the Inject environment variables action to execute the shell script.
Use the Set build description action to set the build description to the variable that was set by the shell script (eg ${BUILD_DESCRIPTION}).
Create an 'Execute system Groovy script' that updates the build description. See How to submit Jenkins job via REST API? which creates a button in the build description.
If I understand correctly, you want a 'Confirmation Button', or a 'Are you Sure' button:
In Jenkins pipeline, you can do that by asking for user input.
timeout(time: 15, unit: "MINUTES") {
input message: 'Are the info correct?'
}
The problem with this approach is that you keep a Jenkins worker (or process) running for a maximum X minute if the user doesn't take any action, this can make Jenkins create a long queue of builds.
Here is the documentation.
If i get what you want to do right (more from the caption and less from the description) you should just use this Publisher Plugin:
if it doesn't help please try adding more information to your question.

Resources