Snippets

Adaptavist Copy Labels To All Linked Issues

Created by Kristian Walker

File copyLabelsToAllLinkedIssues Added

  • Ignore whitespace
  • Hide word diff
+/*
+* This example script  console script shows how you can get the labels off an issue and copy them over to all of its linked issues.
+* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
+* license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
+*/
+
+// Specify the IssueKey
+def issueKey = 'TEST-6'
+
+// Make a rest call to return the Issue
+def issue = get('/rest/api/2/issue/' + issueKey)
+        .header('Content-Type', 'application/json')
+        .asObject(Map)
+        .body
+        
+// Get the labels from the issue        
+def labels= issue.fields.labels
+
+// Find the linked issues
+def linkedIssues = issue.fields.issuelinks
+
+// Loop over each linked issue
+linkedIssues.each{
+// Update each linked issue to set the labels using the key for each linked issue
+def updateLinkedIssue = put('/rest/api/2/issue/' +  it.outwardIssue.key)
+        .header('Content-Type', 'application/json')
+        .body([
+        fields:[
+                labels: labels
+        ]
+])
+        .asString()
+}
+
+return "Labels Updated"
  1. 1
  2. 2
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.