Java——Java连接Jira,创建、修改、删除工单信息

本文介绍了如何使用Java连接并操作Jira,包括获取连接、创建、更新、查询、添加注释和删除工单,以及上传附件。详细步骤和代码示例供参考。
摘要由CSDN通过智能技术生成

还不了解Jira是什么的同学可以看一下这篇文章:https://www.cnblogs.com/wgblog-code/p/11750767.html

本篇文章主要介绍如何使用Java操作Jira,包括获取连接,创建、修改、删除工单信息

1、获取Jira连接并执行请求:

/**
     * 执行shell脚本
     *
     * @param command
     * @return
     * @throws IOException
     */
    private static String executeShell(String command) throws IOException {
        StringBuffer result = new StringBuffer();
        Process process = null;
        InputStream is = null;
        BufferedReader br = null;
        String line = null;
        try {
            //windows平台下用cmd发生请求
            if (osname.indexOf("windows") >= 0) {
                process = new ProcessBuilder("cmd.exe", "/c", command).start();
                System.out.println("cmd.exe /c " + command); //安装Cygwin,使windows可以执行linux命令
            } else {
                //linux平台下执行请求
                process = new ProcessBuilder("/bin/sh", "-c", command).start();
                System.out.println("/bin/sh -c " + command);
            }

            is = process.getInputStream();
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

            while ((line = br.readLine()) != null) {
                System.out.println(line);
                result.append(line);
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            //关闭连接
            br.close();
            process.destroy();
            is.close();
        }

        //返回结果
        return result.toString();
    }

2、获取获得工单信息:

/**
     * 活动工单信息
     *
     * @param issueKey
     *            工单key
     * @return
     * @throws IOException
     */
    public static String getIssue(String issueKey) throws IOException {

        /**
         * jira的请求格式:
         * curl -u 用户名:密码 -X 请求类型 --data @文件的路径 -H "Content-Type: application/json" 请求路径
         * 
         * 官方示例:curl -u admin:admin -X POST --data @data.txt -H "Content-Type: application/json" http://localhost:8080/jira/rest/api/2/issue/
         *
         *  注意:--data后面的 @符合一定不能少
         */

        String command = "curl -D- -u " + user + ":" + pwd
                + " -X GET -H \"Content-Type: application/json\" \"" + uri
                + "/rest/api/2/issue/" + issueKey + "\"";

        String issueSt = executeShell(command);

        return issueSt;

    }

3、创建工单信息:

/**
     * 创建工单
     *
     * @param projectKey
     *            项目key
     * @param issueType
     *            工单类型 name
     * @param description
     *            工单描述
     * @param summary
     *            工单主题
    //     * @param assignee
     *            工单负责人
     *          
     * @return
     * @throws IOException
     */
    public static String createIssue(String projectKey, String issueType,String user,
                                     String description, String summary) throws IOException {

        String command="curl -D- -u " + user + ":" + pwd
                + " -X POST  --data @E:\\data.json -H \"Content-Type: application/json\" \"" + uri
                + "/rest/api/2/issue/\"";

        String issueSt = executeShell(command);

        if (!issueSt.contains("errorMessages")) {
            System.out.println("success");
        }else {
            System.out.println("error")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值