官方文档链接地址:
POST
Transition issue
Performs an issue transition and, if the transition has a screen, updates the fields from the transition screen.
sortByCategory To update the fields on the transition screen, specify the fields in the
fields
orupdate
parameters in the request body. Get details about the fields using Get transitions with thetransitions.fields
expand.This operation can be accessed anonymously.
Permissions required:
- Browse projects and Transition issues project permission for the project that the issue is in.
- If issue-level security is configured, issue-level security permission to view the issue.
Connect app scope required:
WRITE
OAuth 2.0 scopes required:
ClassicRECOMMENDED:
write:jira-work
Granular:
write:issue:jira
,write:issue.property:jira
实用json请求脚本如下:
{"transition": {"id": "%s"},"fields": {"resolution": {"name": "Fixed"}}
}
id参数是通过transitions api来获取的,
可以参考jira获取issue条目transitions id,以用来进行流转实用脚本_锐湃的博客-CSDN博客
示例代码如下:
// The payload definition using the Jackson libraryJsonNodeFactory jnf = JsonNodeFactory.instance;ObjectNode payload = jnf.objectNode();{ObjectNode transition = payload.putObject("transition");{transition.put("id", "81");//"91"}}// Connect Jackson ObjectMapper to UnirestUnirest.setObjectMapper(new ObjectMapper() {private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper= new com.fasterxml.jackson.databind.ObjectMapper();@Overridepublic <T> T readValue(String value, Class<T> valueType) {try {return jacksonObjectMapper.readValue(value, valueType);} catch (IOException e) {throw new RuntimeException(e);}}@Overridepublic String writeValue(Object value) {println("writeValue=====" + value);try {return jacksonObjectMapper.writeValueAsString(value);} catch (JsonProcessingException e) {throw new RuntimeException(e);}}});// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html//"https://your-domain.atlassian.net/rest/api/2/issue/issueIdOrKey/transitions"HttpResponse<JsonNode> response = Unirest.post("https://jira.example.com/rest/api/2/issue/TEST-7/transitions").basicAuth("User", "TOKEN").header("Accept", "application/json").header("Content-Type", "application/json").body(payload).asJson();System.out.println(response.getBody());
本次上送的请求json如下
{"transition": {"id": "81"}
}
执行成功后返回null打印出来,如果没有成功会返回失败的原因
执行成功后会发现issue已关闭
比如现在有一个需求要把TEST项目的处于待验证(已解决)状态的issue关闭;
对于这个需求可以分为三步:
1、通过search issue条目rest api获取到当前处于已解决待验证状态的issue,并把issueKeyOrId收集起来;
可以参考:jira搜索search issue条目rest实用脚本_锐湃的博客-CSDN博客
2、通过issueKeyOrId用transitions rest api获取到transitions id;
可以参考jira获取issue条目transitions id,以用来进行流转实用脚本_锐湃的博客-CSDN博客
3、用上一步获取的的id作为参数调用 文章开头的rest api请求就可以关闭流转issue了