`
xshwlx
  • 浏览: 19507 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jenkins 认证 API 调用

 
阅读更多
  public  static HttpClient getAuthClient() throws IOException {
        HttpClient client = new HttpClient();
        String hostName = jenkinsHost;
        GetMethod loginLink = new GetMethod(hostName+"loginEntry");
        client.executeMethod(loginLink);
        String location = hostName+"j_acegi_security_check";
        PostMethod loginMethod = new PostMethod(location);
        loginMethod.addParameter("j_username", username); // TODO: replace with real user name and password
        loginMethod.addParameter("j_password", pwd);
        loginMethod.addParameter("action", "login");
        client.executeMethod(loginMethod);
        return client;
    }


    public static int jobExist(String jobName) throws IOException {
        int code = 0;
        try {
            HttpClient client = getAuthClient();
            GetMethod post = new GetMethod(jenkinsHost + "job/"+jobName+"/config.xml");
            code = client.executeMethod(post);
        }catch (IllegalArgumentException e){
            code = 1;
            e.printStackTrace();
        }
        return code;
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics