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.
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"))
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.