如何使用jira-python API标记Jira TC的执行状态失败或通过?

时间:2018-09-04 18:36:53

标签: python jira jira-rest-api python-jira

我正在使用jira-python模块并从jira获取TC列表。现在执行后,我想将TC的执行状态标记为失败或通过。如何实现?

我的代码:

jserver = {'server':server}
j = JIRA(options=jserver,basic_auth=(username,password))


total = 5000
end = 0
c=[]
while end <= 5000 :
    issues_in_proj = j.search_issues('project=TC',startAt=end,maxResults=1000)
    print len(issues_in_proj)
    for ticket in issues_in_proj:
        issue = j.issue(ticket)
        labels = issue.fields.labels


def MarkTcExecutionState(testkey):
                   NO Idea which method to use, tried to use transition but it changes issue transition state and not execution state

2 个答案:

答案 0 :(得分:0)

values = {
    "executions": [
        str(test)
    ],
    "status": str(status_id)
}

def mark_test_status(self,testid,values):
    headers = {'Content-Type': 'application/json'}

    s = requests.put(str(self.server) +"/rest/zapi/latest/execution/"+str(testid)+"/execute", auth=(self.username, self.password),data=json.dumps(values), headers=headers)
    print "test marked as per status"

jira-server的其他API: https://getzephyr.docs.apiary.io/#reference/executionresource/update-bulk-execution-status/update-bulk-execution-status

答案 1 :(得分:0)

public  String updateExecution(int executionId, String status) throws Exception {
        System.out.println("Executing execution with executionId " + executionId + " and status = " + status);

        String url = "https://jira.company.com/jira/rest/zapi/latest/execution/" + executionId + "/execute";
        //String url = "https://jira.company.com/jira/rest/zapi/latest/execution";
        String statusInReq = "";

        if (status.equalsIgnoreCase("pass")) {
            statusInReq = "1";
        } else if (status.equalsIgnoreCase("fail")) {
            statusInReq = "2";
        }

        // Create request body
        JSONObject obj = new JSONObject();
        obj.put("status", statusInReq);
        obj.put("comment", "through java");

        String requestBody = obj.toString();
        System.out.println("Request body: " + requestBody);
        HttpURLConnection conn
         = httpPut(url, null, null, obj.toString());
        System.out.println("HTTP response code: " + conn.getResponseCode());
        String response = getResponse(conn);
        System.out.println("HTTP response content: " + response);
        System.out.println("from HTTP response content fetch the execution id: " + response.substring(6, 12));

        return response;
    }