#!/usr/bin/env ruby # # This sample ruby program showcases ways to interact with JIRA application via # JIRA's SOAP interface. # This program is tested on May, 2007. Current version of this sample can be # downloaded from Rubyhaus's Jira4r project's website: # http://xircles.rubyhaus.org/projects/jira4r . # This sample program should be run on ruby/soap4r/jira4r environment. # It is tested with Ruby 1.8.6, SOAP4R-20061022. It supports V2 WSDL # for JIRA professional version and JIRA enterprise version. # To setup the environment: # 1. Download Ruby from http://www.ruby-lang.org/en and compile/install it. # 2. Download SOAP4R from http://dev.ctor.org/soap4r and gem build/install it. # (Note that the SOAP4R library included in Ruby version 1.8.6 is version # 1.5.5. Jira4R requires SOAP4R code later than 20061022. # 3. Download Jira4R from Jira4r project's website, and follow the # REAME.txt file. # ALL JIRA's SOAP APIs are exposed via Jira4R. Description of JIRA's SOAP # APIs (Javadoc) is at: # http://www.atlassian.com/software/jira/docs/ # api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/JiraSoapService.html. # In addition, Jira4R exposes these additional 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 ) #If running as part of distribution require File.dirname(__FILE__) + '/../lib/jira4r/jira4r.rb' #If using GEM install #require 'jira4r/jira4r' # Create a new JiraTool # # where: # version ... the version of the SOAP API you wish to use - currently supported versions [ 2 ] # base_url ... the base URL of the JIRA instance - eg. http://confluence.atlassian.com jira = Jira::JiraTool.new(2, "http://jira.atlassian.com") baseurl = jira.getServerInfo().baseUrl puts "Base URL: " + baseurl , "\n" jira.login("soaptester", "soaptester") projectKey = "DEMO" puts "Details for project " + projectKey + ":" puts jira.getProject(projectKey).inspect , "\n" issueKey = "TST-10392" issue = jira.getIssue(issueKey) puts "Retrieved issue: " + issue.key , "\n" # 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" # 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 # 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 # Create user. The second parameter is password string. begin user = jira.createUser("jon", `date`.strip, "Jon Happy", "jon@usa.com") puts "Created user " + user.name , "\n" rescue end # Get details of a group groupname = "jira-users" begin group = jira.getGroup("jira-users") puts "Retrieved details for group " + groupname + ":" puts group.inspect , "\n" rescue end # 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 # 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 # List all projects key jira.getProjects().each { |project| puts project.key }