jirapython-jira

How can i set release to "Released" in JIRA


I have a Board named ASDF, In that board under Relaeses tab I have a Version named: QWER. This version has 3 issues.

I want to change the status of the version to "Released" if all the issues are in "done" state. I don't know how to change the status to "Released".

I am trying to do this using JIRA-Python REST-API. I am also open to CLI method.


Solution

  • The best method for accomplishing this would be via the Jira Automation Plugin. Keep in mind I have no affiliation with this plugin; However, I do have experience using it, and it would suit this purpose perfectly. On to the python-jira solution, keep in mind this will be much more difficult. First you must check that all issues are done, this can be done via:

    def version_count_unresolved_issues(self, id):
            """Get the number of unresolved issues for a version.
    
            :param id: ID of the version to count issues for
            """
            return self._get_json('version/' + id + '/unresolvedIssueCount')['issuesUnresolvedCount']
    

    So we check via some conditional as follows:

    if not jira.version_count_unresolved_issues('QWER'):
        jira.move_version(...)
    

    The move_version function looks like:

    def move_version(self, id, after=None, position=None):
            """Move a version within a project's ordered version list and return a new version Resource for it.
    
            One, but not both, of ``after`` and ``position`` must be specified.
    
            :param id: ID of the version to move
            :param after: the self attribute of a version to place the specified version after (that is, higher in the list)
            :param position: the absolute position to move this version to: must be one of ``First``, ``Last``,
                ``Earlier``, or ``Later``
            """
            data = {}
            if after is not None:
                data['after'] = after
            elif position is not None:
                data['position'] = position
    
            url = self._get_url('version/' + id + '/move')
            r = self._session.post(
                url, data=json.dumps(data))
    
            version = Version(self._options, self._session, raw=json_loads(r))
            return version
    

    Regarding your comment take a look at this excerpt from the docs:

    from jira import JIRA
    import re
    
    # By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK
    # (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details).
    # Override this with the options parameter.
    options = {
        'server': 'https://jira.atlassian.com'}
    jira = JIRA(options)
    

    You don't pass self anywhere, you simply call the jira instance's functions like so:

    jira.version_count_unresolved_issues('QWER')
    

    You don't pass self at all, the jira instance is automatically passed as self behind the scenes, please take a look at the python-jira docs for more information: https://jira.readthedocs.io/en/master/examples.html