jenkins authentication API call

  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;
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326244827&siteId=291194637