/** * get latest build number * * @param jobName * @return * @throws JSONException */ public int getLastBuildNumber(String jobName) throws JSONException { String getUrl = jenkinsUrl + "/job/" + jobName + "/lastBuild" + API; JSONObject responseJson = runHttp(client, context, getUrl); return responseJson.getInt("number"); }
/** * check if build finished * * @param jobName * @param buildNumber * @return * @throws JSONException */ public boolean isBuildFinished(String jobName, int buildNumber) throws JSONException { String getUrl = jenkinsUrl + "/job/" + jobName + "/" + buildNumber + API; JSONObject responseJson; responseJson = runHttp(client, context, getUrl); if (responseJson == null) { return false; } return (!Boolean.parseBoolean(responseJson.getString("building")) && responseJson.getInt("duration") > 0); }