3
votes

We're trying to automate this task in our release process so that our scripts add a new released version in Jira. It will then iterate through a list of jira issues that have 'shipped' in this release and tag them with the Release Version we just added.

I can't seem to find any examples of adding a new Released Version in Jira [Project > Releases] via REST API.

Can you please share how you are handling this?

2

2 Answers

4
votes

Add new Released Version via Jira API code snippet using ruby with httparty.

 require 'httparty'

 def self.create_version(version)
    create_version_url = "https://jira2.server.com/rest/api/2/version"

    @result = HTTParty.post(create_version_url,
       :basic_auth => {:username => 'user', :password => 'password'},
       :body => { :description => '',
                  :name => version,
                  :archived => false,
                  :released => true,
                  #:releaseDate => "2016-07-06",
                  :userReleaseDate => "6/Jul/2017",
                  :project => "project_name",
                  :projectId => "10102"
                }.to_json,
       :headers => { 'Content-Type' => 'application/json' })
   puts @result
 end

Set Fixed Version of jira issue:

def self.set_issue_fixedVersion(ticket,fixedVersion)       
   edit_issue_url = "https://jira2.<server>.com/rest/api/2/issue/#{ticket}"

   @result = HTTParty.put(edit_issue_url,
   :basic_auth => {:username => 'user', :password => 'password'},
   :body => { "fields" => { "fixVersions"=> [{"name" => #{fixedVersion}}]}}.to_json,
   :headers => { 'Content-Type' => 'application/json' })
   puts @result
end
2
votes

Could be something like this:

  • Create the new version: POST /version

    • You will also have to specify the project that the version belongs to

    • This will also make the version show up on the Project -> Releases page

  • Search for fixed issues, so you have their issue keys: POST /search

    • Possibly you can also get this list in another way, ie. from your version control system
  • Update the fixVersion of those issues with your new version: /PUT issue/{issueIdOrKey}

  • Release your version: PUT /version/{id}

    • In the body of your request specify the releaseDate and set released to true