Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA Cloud Edit Issues Script

Zachary Casey
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2019

I'm looking for ways to automate bulk editing of issues using scripts. Ideally, I'd like the script to pull info from an Excel spreadsheet weekly and push these details to existing JIRA tickets. I am a beginner in this regard, but I need to automate some of my work...starting to lose my mind!

Any guidance or suggestions would be amazing. I did start reading through the JIRA Cloud REST API documentation, but unfortunately I just don't know where to start.

1 answer

0 votes
Larry Talley
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2019

I like scripting Jira using Ruby. I'll paste an example script. It isn't a completely trivial exercise, as you have to get a Ruby environment installed, know some Ruby syntax and understand the Jira API, and web API access presents multiple failure modes.

But the rewards may make the effort worthwhile.

#!/usr/bin/env ruby
#require 'highline/import'
require 'rubygems'
require 'json'
require 'jira-ruby'

# Program parameters
projectKey = "TEST"
linkToKey = "AFP"
originalYear = "2018-19"
newYear = "2018-19"

# Fixed parameters
jiraBaseUrl = "https://abc.com/jira"
jiraRestUrl = "https://abc.com/jira/rest/api/latest/"
jiraSiteUrl = "https://abc.com"
jiraUsername = "abc"
jiraPassword = "abc"

#jql="project=#{projectKey} and labels in (#{originalYear}) and labels not in (#{newYear}) and component = Crab order by summary"
jql="project=#{projectKey} and component = Crab order by summary"
issueJqlTemplate = "project=#{linkToKey} and component = Crab and labels not in (#{newYear}) and text ~ "

modelIssueJql="key=TEST-432"
fields="key"
options = {
:username => jiraUsername,
:password => jiraPassword,
:site => jiraSiteUrl,
:context_path => '/jira',
:auth_type => :basic,
# :http_debug => true,
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE
}
search="search?jql=" + jql + "&fields=" + fields
json_ext = ".json"

# Query JIRA and process a result set

printf("Relabel.rb executing at %s with JQL %s.\n", Time.now.strftime("%Y/%d/%m %H:%M"), jql)
client = JIRA::Client.new(options)
issues = client.Issue.jql(jql)

modelIssues = client.Issue.jql(modelIssueJql)
printf("Query returned %d issues.\n",issues.size)

processedCount = 0

issues.each do |issue|

#p issue.fields["issuelinks"]
summaryWords = issue.fields["summary"].downcase.split
priorYearLinkJql = issueJqlTemplate + '"' + summaryWords[2] + " " + summaryWords[3] + '"'
priorYearLinkIssues = client.Issue.jql(priorYearLinkJql)
#printf("Prior year query %s returned %d issues.\n",priorYearLinkJql,priorYearLinkIssues.size)
priorYearLinkIssues.each do |linkToIssue|
#printf("Making link to %s.\n",linkToIssue.attrs["key"])
newLink = client.Issuelink.build
newLink.save({:type=>{:name=>"relates to"}, :inwardIssue=>{:key=>issue.attrs["key"]}, :outwardIssue=>{:key=>linkToIssue.attrs["key"]}})
printf("Linked %s to %s.\n", issue.attrs["key"], linkToIssue.attrs["key"])
processedCount = processedCount + 1
end
end

printf("Completed processing, linked %d issues at %s.\n",processedCount, Time.now.strftime("%Y/%d/%m %H:%M"))

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence administration certification, atlassian certified professional, confluence admin for cloud, atlassian learning, confluence training, confluence certification exam, confluence cloud admin, admin credential, atlassian certification

Become a certified Confluence admin today! 📖

Stand out as a skilled Confluence Cloud administrator. The Confluence Administration for Cloud certification proves you can configure permissions, manage site and space settings, and monitor activity—ensuring secure, effective collaboration for your team.

Start here
AUG Leaders

Atlassian Community Events