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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章