Snippets

Adaptavist Copy Labels To All Linked Issues

Updated by Kristian Walker

File copyLabelsToAllLinkedIssues.groovy Modified

  • Ignore whitespace
  • Hide word diff
 println "Iteration ${loopCounter} of the loop set the labels on the ${it.outwardIssue.key} issue."
 }
 
-return "The Script has completed updating the labels succsfully. \nPlease see the 'Logs' tab for more information on what issues were updated."
+return "The Script has completed updating the labels succsfully on ${loopCounter} issues. \nPlease see the 'Logs' tab for more information on what issues were updated."
Updated by Kristian Walker

File copyLabelsToAllLinkedIssues.groovy Modified

  • Ignore whitespace
  • Hide word diff
 def linkedIssues = issue.fields.issuelinks
 
 // Define a loop counter
-def loopCounter = 0;
+def loopCounter = 0
 
 // Loop over each linked issue
 linkedIssues.each{
Updated by Kristian Walker

File copyLabelsToAllLinkedIssues.groovy Modified

  • Ignore whitespace
  • Hide word diff
 */
 
 // Specify the IssueKey
-def issueKey = 'TEST-6'
+def issueKey = '<InsertIssueKeyHere>'
 
 // Make a rest call to return the Issue
 def issue = get('/rest/api/2/issue/' + issueKey)
Updated by Kristian Walker

File copyLabelsToAllLinkedIssues.groovy Modified

  • Ignore whitespace
  • Hide word diff
 */
 
 // Specify the IssueKey
-def issueKey = '<IssuekeyHere>'
+def issueKey = 'TEST-6'
 
 // Make a rest call to return the Issue
 def issue = get('/rest/api/2/issue/' + issueKey)
 // Find the linked issues
 def linkedIssues = issue.fields.issuelinks
 
+// Define a loop counter
+def loopCounter = 0;
+
 // Loop over each linked issue
 linkedIssues.each{
+
+// Iterate the loop counter on each iteration of the loop
+loopCounter ++
+
 // 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')
         ]
 ])
         .asString()
+
+// Print to the log tabs what iteration the loop  is on and the key of the issue that was updated        
+println "Iteration ${loopCounter} of the loop set the labels on the ${it.outwardIssue.key} issue."
 }
 
-return "Labels Updated"
+return "The Script has completed updating the labels succsfully. \nPlease see the 'Logs' tab for more information on what issues were updated."
Updated by Kristian Walker

File copyLabelsToAllLinkedIssues Deleted

  • 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"

File copyLabelsToAllLinkedIssues.groovy 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 = '<IssuekeyHere>'
+
+// 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.