I’m working with the jira-ruby gem to fetch and modify issue statuses in Jira. I found some examples online and tried implementing this approach:
require 'jira'
require '../config/auth'
credentials = {
:username => $jira_user,
:password => $jira_pass,
:site => "https://mycompany.atlassian.net",
:context_path => '',
:auth_type => :basic
}
jira_client = JIRA::Client.new(credentials)
ticket = jira_client.Issue.find("PROJECT-2341")
possible_transitions = jira_client.Transition.all(:issue => ticket)
possible_transitions.each {|transition| puts "#{transition.name} (id #{transition.id})" }
The script runs without errors but doesn’t display any transitions. I added some debug output to the transition.rb file in the gem:
pp path
pp response.body
When I run the script again, I see:
"https://mycompany.atlassian.net/rest/api/2/issue/12345/transitions"
"{\"expand\":\"transitions\",\"transitions\":[]}"
The weird thing is that when I paste that URL directly into my browser, I get back valid JSON with all the available transitions for the ticket. The API endpoint works fine manually, but the gem seems to get an empty response. Has anyone encountered this issue before?
It seems the jira-ruby gem is not maintaining your authentication properly. A good approach is to try sending the authentication headers directly with your transition request. Additionally, you can expand transitions when fetching them, which might help. For example:
possible_transitions = jira_client.Transition.all(:issue => ticket, :expand => 'transitions')
Alternatively, reloading the issue before attempting to get transitions could resolve the empty response issue:
ticket = jira_client.Issue.find("PROJECT-2341")
ticket.reload!
possible_transitions = jira_client.Transition.all(:issue => ticket)
This ensures the issue context is refreshed.
sounds like a session/cookie problm. the gem probably isn’t handling auth state properly between requests. try making a fresh client instance right before calling the transition, or check if your session’s expiring. also double-check your JIRA permissions for viewing transitions - the API sometimes acts different than browser access.
Had this exact problem! The jira-ruby gem screws up the request parameters sometimes - doesn’t send the right headers or query params that Jira’s transitions endpoint needs. Skip the Transition.all method completely and hit the API directly: jira_client.get("/rest/api/2/issue/#{ticket.key}/transitions"). You’ll get the raw response and way more control. The gem’s wrapper often misses transitions that the direct call catches. The abstraction layer gets weird with certain Jira setups, especially cloud instances.