Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JIRA - Jira post function -- How to update "fix version" field?

Tags:

java

plugins

jira

My scenario is: One step in my jira workflow should have the ability to unschedule a task i.e. set a Fix Version to "None".

I noticed that I was not able to update fix version in a workflow post function - I don't know exactly why, but anyway I did implement a jira plugin to help me solve my problem but I know I'm going against jira structure (even java good coding practices :)). I am not sure if my implementation can cause problems, but indeed it is working in my jira instance 4.1.x.

How I've implemented a plugin to update fix version in a post function, 2 very similar ways:

public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
    // Here I create an empty Collection to be the new value of FixVersion (empty because I need no version in Fix Version)
    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
        MutableIssue issue = this.getIssue(transientVars);
        Collection<Version> newFixVersion = new ArrayList<Version>();
            issue.setFixVersions(newFixVersion);
            issue.store();
    }
}

public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
    // here I clear the Collection I got from "old" Fix Version and I have to set it again to make it work.
    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
        MutableIssue issue = this.getIssue(transientVars);
        Collection fixVersions = issue.getFixVersions();
        fixVersions.clear();
        issue.setFixVersions(fixVersions);
        issue.store();
    }
}

I presume that a real solution should use classes like: ChangeItemBean, ModifiedValue, IssueChangeHolder - taking as example the updateValue methods from CustomFieldImpl (from jira source code, project: jira, package: com.atlassian.jira.issue.fields).

My point of publishing this here is:

  • Does anyone know how to implement a jira plugin containing a post function to change Fix Version correctly?
like image 721
gege Avatar asked Jan 27 '11 18:01

gege


2 Answers

If you want to do it properly take a look in the code for

./jira/src/java/com/atlassian/jira/workflow/function/issue/UpdateIssueFieldFunction.java processField()

Postfunctions that take input parameters are not documented yet it seems. Other places to go for code are other open source plugins.

like image 101
mdoar Avatar answered Oct 16 '22 00:10

mdoar


Atlassian has a tutorial on doing just about exactly what you want to do, here:

like image 24
CXJ Avatar answered Oct 15 '22 23:10

CXJ