Overview
This document provides recipes for your needs to adminstrate your JIRA instances programmatically. Your comments/contributions are very welcome as they make our Jira/Ruby community a better place for all.
Sample scripts can be found at examples directory of Jira4R projects' source code repository. irb (interactive ruby) can be used to verify the recipes quickly:
[zzx@zug jira4r]$ pwd /home/zzx/download/jira4r.new/jira4r/trunk/lib/jira4r [zzx@zug jira4r]$ irb irb(main):001:0> require "jira4r.rb" => true irb(main):002:0> jira = Jira::JiraTool.new(2, "http://jira.atlassian.com") cannot find mapped class: Byte => #<Jira::JiraTool:0x404afaac @endpoint_url="http://jira.atlassian.com/rpc/soap/jirasoapservice-v2", @base_url="http://jira.atlassian.com", @version=2, @logger=#<Logger:0x404afa84 @logdev=#<Logger::LogDevice:0x404afa34 @filename=nil, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x404afa0c @mon_owner=nil, @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0>, @dev=#<IO:0x400a3f58>, @shift_size=nil, @shift_age=nil>, @formatter=nil, @default_formatter=#<Logger::Formatter:0x404afa5c @datetime_format=nil>, @level=0, @progname=nil>, @enhanced=false> irb(main):003:0> jira.login("soaptester", "soaptester") I, [2007-05-07T11:43:00.980257 #21935] INFO -- : Connecting driver to http://jira.atlassian.com/rpc/soap/jirasoapservice-v2 => "482eTez0M7" irb(main):004:0>
Jira4R interacts with JIRA instances via its SOAP interface:
Atlassian's documentation about web service interface
Atlassian's documentation about SOAP interface
In addition, there are these additional ways to access your Jira instance:
All Jira's SOAP APIs are exposed via Jira4R. In addtion, Jira4R exposes these methods:
* getProjectNoScheme( projectKey )
* getProject( projectKey )
* getNotificationScheme( notificationSchemeName )
* getGroup( groupName )
* getGroupRoleByName( projectRoleName )
* createPermissionScheme( name, description )
* getPermissionScheme( permissionSchemeName )
* getNotificationScheme( notificationSchemeName )
* getPermission( permissionName )
* findPermission( allowedPermissions, permissionName )
* fineEntityInPermissionMapping( permissionMapping, entityName )
* setPermissions( permissionScheme, allowedPermissions, entity )
Recipes
- How to get details of a project with project name?
projectKey = "DEMO" puts "Details for project " + projectKey + ":" puts jira.getProject(projectKey).inspect , "\n"
- How to retrieve values of a custom field
# Retrieves custom field values for custom field with ID 10083 # The custom field ID can be found via SQL command: # select id from customfield where cfname = "your custom field name" customfieldID = "customfield_10150" puts "Value of issue " + issue.key + "'s custom field with ID " + customfieldID + ":" customFieldValues = issue.customFieldValues customFieldValues.each { |cf| puts cf.values if cf.customfieldId == "customfield_10150" } puts "\n"
- How to add comment
comment = RemoteComment.new() comment.body = "commented from jira4r" begin jira.addComment(issue.key, comment) puts "Added comment " + comment.body + " in issue " + issue.key , "\n" rescue end
- How to change field value
summary = RemoteFieldValue.new("summary", "new summary info from jira4r") begin jira.updateIssue(issue.key, summary) puts "Updated issue " + issue.key + "'s field " + summary.id , "\n" rescue end
- How to create a user
begin user = jira.createUser("jon", `date`.strip, "Jon Happy", "jon@usa.com") puts "Created user " + user.name , "\n" rescue end
- How to add a new user to a group
# Add user to a group # This issue and workaround is documented at JRA-7971 begin newuser = RemoteUser.new() newuser.name = user.name jira.addUserToGroup(group,newuser) puts "Added user " + user.name + " in group " + group.name rescue end
- How to add a new version
version = RemoteVersion.new() version.name = "version 99" begin jira.addVersion(project.name, version) puts "Added version " + version.name + " for group " + group.name rescue end
- How to list all projects' keys
jira.getProjects().each { |project| puts project.key }

