Jenkins pipeline dynamic choice parameter list for active checkboxes - jenkins

I have a pipeline job where I want to execute Selenium tests on multiple browsers depending on the user parameters selection. Currently I have an extended choice parameter with checkboxes:
parameters{
extendedChoice(defaultValue: 'Chrome', description: 'Tests will run at the default resoluton of 1024x768', descriptionPropertyValue: '', multiSelectDelimiter: ',', name: 'Browsers', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: 'Chrome, Firefox, IE, Edge, Safari', visibleItemCount: 5) }
What I want to do is also add a single choice selection for each checked browser, consisting of browser supported versions, basically sending a map of browser-version key/values. I tried also with Active choice parameters but with no luck.
https://i.stack.imgur.com/GNwM8.jpg

Related

Mandatory Jenkins parameter

I would like to know how to make a parameter mandatory in Jenkins, so the "Build" button is unavailable until someone fills it.
[$class: 'hudson.model.StringParameterDefinition', defaultValue: 'master', description: 'Description', name: 'repositoryTag'],
I have this, and I was wondering if there is something I could do such as adding "required: True" for example.

Assign multiple issues in Jira using Jenkins

I am trying to move and assign multiple issues from Jira using Jenkins
ticketID= jiraIssueSelector(issueSelector: [$class: 'JqlIssueSelector', jql: 'some JQL queries'])
step([$class: 'JiraIssueUpdateBuilder', jqlSearch: "someJQLqueries", workflowActionName: 'Done'])
jiraAssignIssue idOrKey: ticketID, userName: null, failOnError: false
The first step where I am changing the workflow is working fine. However, I can not change the assignee I am getting the bellow message. Is there a way to use the Jira plugin instead of the Jira plugin step to update a non-custom field?
java.lang.ClassCastException: org.thoughtslive.jenkins.plugins.jira.steps.AssignIssueStep.idOrKey expects class java.lang.String but received class java.util.HashSet
I also tried the following and it is not working:
step([$class: 'IssueFieldUpdateStep', fieldId: 'assignee', fieldValue: 'someUser', issueSelector: [$class: 'JqlIssueSelector', jql: 'some JQL query']])
I found the answer to loop through all the tickets in the jql:
ticketID= jiraIssueSelector(issueSelector: [$class: 'JqlIssueSelector', jql: 'some JQL queries'])
ticketID.each{ ticket ->
jiraAssignIssue idOrKey: ticket, userName: null, failOnError: false
}

Parameters control in jenkins using pipelines as code

Can we write like this in pipeline script?. Need to populate the string by choice parameter. I am new to Jenkins world.
parameters { choice(name: 'CHOICE', choices: ['FirstName', 'LastName'], description: 'Pick something') }
script {
if (${CHOICE} == "FirstName")
{
parameters { string(name: 'FirstName', defaultValue: '', description: 'This is FirstName')}
}
else
{
parameters { string(name: 'LastName', defaultValue: '', description: 'This is LastName') }
}
}
Is there any other way to do it inside the jenkins? Any plugin which can help!
It's a bit unclear what exactly you are trying to achieve.
If what you want is interactivity — when you make a choice in the dropdown box, the contents of another parameter changes based on your choice — then ActiveChoice plugin can help you with that.
If you want to define different params as depending on your choice of the first one, then it's not possible. Jenkins needs to fully parse your Jenkinsfile (parameters and all) in order to present you with the parameters screen, but you seem to want to define your parameters based on the results of the presentation. This is a kind of a chicken and egg problem here.

how can I pop an input box for a specific choice?

In jenkins I'd like to do this:
parameters {
choice(
name: 'blah',
choices: 'one\ntwo\ncustom',
description: 'if you choose custom enter a custom number'
)
}
So they have three options on the drop down, but it would be nice if when they select the "custom" choice jenkins pops an input box to type in raw user input.
Is this possible? I don't want to use user input during the pipeline run because that means they need to choose custom then wait for jenkins to get to the stage where it asks them for input.
Yep, Once the build starts, check the value of params.blah and throw up an input step with a String param, so
if (params.blah == 'custom' ) {
timeout(time: 1, unit: 'minute') { // change to a convenient timeout for you
userInput = input(
id: 'Proceed1', message: 'Custom value?', parameters: [
[$class: 'StringParameterDefinition', defaultValue: '',
description: 'Enter Custom value', name: 'Value']
])
}
}

How do I run a Jenkins job where user can enter a date value?

I wanted to run a jenkins job by accepting a date field (in format YYYY-MM-DD) from user. I found a link where user can enter a string parameter:
job('example') {
parameters {
stringParam('myParameterName', 'my default stringParam value', 'my description')
}
}
But in string param user can enter any thing. So how do I force user to enter a date field like a calender field and select date from the calender ?
There seems to be no plugin which provides a date chooser.
But you can use the Validating String Parameter Plugin, which can use a regular expression to validate a string parameter. See Regex to validate date format dd/mm/yyyy for regular expressions matching date values.
The Job DSL plugin has no built-in support for the Validating String Parameter Plugin, but you can use a Configure Block to add the relevant config XML.
job('example') {
configure { project ->
project / 'properties' / 'hudson.model.ParametersDefinitionProperty' / parameterDefinitions << 'hudson.plugins.validating__string__parameter.ValidatingStringParameterDefinition' {
name('DATE')
description('date in YYYY-MM-DD format')
defaultValue('2016-03-01')
regex(/\d\d\d\d-\d\d-\d\d/)
failedValidationMessage('Enter a YYYY-MM-DD date value!')
}
}
}
I came across this same issue today and this is how I solved it.
Using: Active Choice Plugin
In a Declarative Pipeline I added the following parameter
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HIDDEN_HTML',
description: '',
name: 'YOUR_PARAMETER_NAME',
omitValueField: true,
referencedParameters: '',
script: [
$class: 'GroovyScript',
fallbackScript: [classpath: [], sandbox: false, script: ''],
script: [
classpath: [],
sandbox: false,
script: 'return "<input type=\\"date\\" name=\\"value\\" value=\\"\\" />"'
]
]
]
Basically it adds an HTML Input Element of type Date, which you can then catch the value during the run.
pipeline {
agent { label "master" }
stages {
stage('Output Date') {
steps {
script {
println params.YOUR_PARAMETER_NAME
}
}
}
}
}
Here's a picture of how it looks on Chrome:
HTML Date parameter
Note: You can also use it to add parameters of type TextArea and so on.

Resources