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
}
Related
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.
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
In my Jenkins multi pipeline project i am having a input step like this:
input message: 'Merge', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: "Merge ${branchConfig.merge} to ${env.BRANCH_NAME}?"]]
I am starting this job by calling this url:
http://user:api-token#awesome.jenkins.de/job/myTest/job/dev/build
Now I want to add a GET parameter like this:
http://user:api-token#awesome.jenkins.de/job/myTest/job/dev/build?skipInput=true
My question now is, how can I get this parameter in groovy?
UPDATE: Following the first comment, I did the following:
// Add parameter to skip MergeInput.
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'BooleanParameterDefinition', name: 'skipMergeInput', defaultValue: false]]]])
And adjusted the input like that:
input message: 'Merge', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: params.skipMergeInput, description: '', name: "Merge ${branchConfig.merge} to ${env.BRANCH_NAME}?"]]
When I am now starting my job, it shows me a popup that ask for the value that should be set. But no matter what i decide, the input is always false. I am trying to figure out what is going wrong and will update my post then.
UPDATE 2:
So I kept on debugging. I added the following to my groovy script:
// Add parameter to skip MergeInput.
def doMerge = properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'BooleanParameterDefinition', name: 'doMerge', defaultValue: true]]]])
println doMerge;
The output returns me NULL, and when I am doing something like
println params.doMerge
It tells me that params is not defined. Any idea what is going wrong?
UPDATE 3:
Call URL: /job/dg_test/job/master/buildWithParameters?test=true
Groovy Script:
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'BooleanParameterDefinition', name: 'test', defaultValue: false]]]])
println params.test
Result:
No such property: params for class: groovy.lang.Binding
I finally solved it, this post really helped me: https://stackoverflow.com/a/41276956/1565249
And this is my implementation:
// Add fancy build parameter.
properties([
parameters([
booleanParam(
defaultValue: false,
description: 'Some description',
name: 'developmentMerge'
),
])
])
if (developmentMerge == "true" || developmentMerge == true) {
// Your code here
}
else {
// Your code here
}
When I now start my job manually from the GUI, it asks me which value should be set for "developmentMerge".
And I also can start my job by calling this URL:
"/job/dg_test/job/master/buildWithParameters?developmentMerge=true"
Where "dg_test" is the name of my Jenkins project and "master" is the job i wanted to start.
The if statement must be done like this:
if (developmentMerge == "true" || developmentMerge == true)
because when you start the job from GUI, it will send a boolean "true", but when you start the job by the URL call, you receive a string.
This is achievable in 3 simple steps:
Set a boolean parameter for your pipeline build:
Use the "params." prefix to access your parameter in your input message step:
input message: 'Merge', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: params.skipInput, description: '', name: "Merge ${branchConfig.merge} to ${env.BRANCH_NAME}?"]]
Use the "buildWithParameters" api command rather than "build":
http://user:api-token#awesome.jenkins.de/job/myTest/job/dev/buildWithParameters?skipInput=true
We have a custom field called Internal Deadline in our JIRA but how do I find all issues that has already been Closed but has surpassed its deadline?
{
id: "customfield_6524",
name: "Internal Deadline",
custom: true,
orderable: true,
navigable: true,
searchable: true,
clauseNames: [
"cf[6524]",
"Internal Deadline"
],
schema: {
type: "date",
custom: "com.atlassian.jira.plugin.system.customfieldtypes:datepicker",
customId: 6524
}
}
I have no problem in checking where we have missed the deadline now() but I want the historical data too but there is no possibility to chose my Closed status in the JQL:
Trying to put the Resolved date results in this error:
Date value 'Resolved' for field 'Internal Deadline' is invalid.
Valid formats include: 'YYYY/MM/DD', 'YYYY-MM-DD', or a period
format e.g. '-5d', '4w 2d'.
Maybe JIRA has only been designed with the here-and-now date in scope? I had hoped I could monitor the "delivery track record".
You should download Script runner plugin (free), that provides some already implemented functions for JQL querying. Once you have it installed, you just can use this query:
issueFunction in dateCompare("","Internal Deadline < Resolved")
For further reference see the docs for dateCompare here, https://scriptrunner.adaptavist.com/latest/jira/jql-functions.html#_datecompare
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.