Jenkins pipeline and JIRA: Add multiple lables to issue

Adrian Wyssmann September 12, 2018

I have string (comme separated values) of labels which I want to add to an existing issue using jiraEditIssue within a Jenkins pipeline. The labels are defined as follows

jiraLabels = "Label1,Label2,Label3"

So how to I add all lables to the issue

def modIssue = [fields: [
project: [key: jiraProjectKey],
   labels: [ jiraLabels ]
]]
response = jiraEditIssue idOrKey: currentIssueKey, issue: modIssue

 

2 answers

1 accepted

0 votes
Answer accepted
Adrian Wyssmann September 12, 2018

Simple solution

String[] myLabels = jiraLabels.split(",")
try {
def modIssue = [fields: [
project: [key: jiraProjectKey],
labels: myLabels
]]
response = jiraEditIssue idOrKey: currentIssueKey, issue: modIssue
0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2018

Hello @Adrian Wyssmann

For the labels you might have to use the "add attribute" as it's an array field.

Please see here

{ "update": { "labels": [ {"add": "newlabel"} ] } }

https://developer.atlassian.com/server/jira/platform/updating-an-issue-via-the-jira-rest-apis-6848604/

Adrian Wyssmann September 16, 2018

Yeah but I don't use the REST api directly but rather the jenkins plugin.

sagrawal November 21, 2019

@Adrian Wyssmann  - I am also using the jenkins plugin, but unable to add labels. I am able to add comments to jira but not labels. Not using the rest api. Were you able to solve this issue? @Tarun Sapra  Using Jira Cloud with Jenkins Pipeline, if that makes any difference

sagrawal November 21, 2019

Here is the code snippet:

stage('jira comment')                {                    steps{                        step([$class: 'hudson.plugins.jira.JiraIssueUpdater'                        issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector'],                         scm: scm,                        labels: ["IN-DEV"]])                    }                }

Suggest an answer

Log in or Sign up to answer