/** * Closes underlying resources. * Closed instances should no longer be used * Closing an already closed instance has no side effects */ @Override public void close() { client.close(); }
/** * The ComputerSet class will give informations like * {@link ComputerSet#getBusyExecutors()} or the * {@link ComputerSet#getTotalExecutors()}. * * @return {@link ComputerSet} * @throws IOException in case of an error. */ public ComputerSet getComputerSet() throws IOException { return client.get("computer/?depth=2", ComputerSet.class); }
/** * Get a file from workspace. * * @param fileName The name of the file to download from workspace. You can * also access files which are in sub folders of the workspace. * @return The string which contains the content of the file. * @throws IOException in case of an error. */ public String getFileFromWorkspace(String fileName) throws IOException { InputStream is = client.getFile(URI.create(url + "/ws/" + fileName)); ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) != -1) { result.write(buffer, 0, length); } return result.toString("UTF-8"); }
/** * @return {@link JenkinsVersion} */ public JenkinsVersion getVersion() { if (!client.isJenkinsVersionSet()) { // Force a request to get at least once // HttpHeader. The header contains the version // information. isRunning(); } JenkinsVersion jv = new JenkinsVersion(client.getJenkinsVersion()); return jv; }
private void stopPost(boolean crumbFlag) throws HttpResponseException, IOException { client.post(url + "stop", crumbFlag); }
public void changeOfflineCause(String cause, boolean crumbFlag) throws IOException { String name; if ("master".equals(displayName)) { name = "(master)"; } else { name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); } Map<String, String> data = new HashMap<String, String>(); data.put( "offlineMessage", cause ); client.post_form("/computer/" + name + "/changeOfflineCause?", data, crumbFlag); }
/** * Update the xml description of an existing job * * @param folder the folder. * @param jobName the name of the job. * @param jobXml the job xml configuration. * @param crumbFlag true/false. * @throws IOException in case of an error. */ public void updateJob(FolderJob folder, String jobName, String jobXml, boolean crumbFlag) throws IOException { client.post_xml(UrlUtils.toJobBaseUrl(folder, jobName) + "/config.xml", jobXml, crumbFlag); }
/** * Runs the provided groovy script on the server and returns the result. * * This is similar to running groovy scripts using the script console. * * In the instance where your script causes an exception, the server still * returns a 200 status, so detecting errors is very challenging. It is * recommended to use heuristics to check your return string for stack * traces by detecting strings like "groovy.lang.(something)Exception". * * @param script The script to run. * @param crumbFlag <code>true</code> to add <b>crumbIssuer</b> * <code>false</code> otherwise. * @return results The results of the run of the script. * @throws IOException in case of an error. */ public String runScript(String script, boolean crumbFlag) throws IOException { return client.post_text("/scriptText", "script=" + script, ContentType.APPLICATION_FORM_URLENCODED, crumbFlag); }
formData.add(new BasicNameValuePair("start", Integer.toString(bufferOffset))); String path = getUrl() + "logText/progressiveText"; HttpResponse httpResponse = client.post_form_with_result(path, formData, false);
private void stopPost() throws HttpResponseException, IOException { client.post(url + "stop"); }
/** * Update the <code>description</code> of a Job. * * @param description The description which should be set. If you like to * set an empty description you should use * {@link #EMPTY_DESCRIPTION}. * @param crumbFlag <code>true</code> or <code>false</code>. * @throws IOException in case of errors. */ public void updateDescription(String description, boolean crumbFlag) throws IOException { Objects.requireNonNull(description, "description is not allowed to be null."); ImmutableMap<String, String> params = ImmutableMap.of("description", description); client.post_form(this.getUrl() + "/submitDescription?", params, crumbFlag); }
public void updateView(String viewName, String viewXml, boolean crumbFlag) throws IOException { client.post_xml("/view/" + EncodingUtils.encode(viewName) + "/config.xml", viewXml, crumbFlag); }
/** * This will give you back the {@link PluginManager}. * * @return {@link PluginManager} * @throws IOException in case of a failure. */ public PluginManager getPluginManager() throws IOException { return client.get("pluginManager/?depth=2", PluginManager.class); }
/** * Cancels the Quiet Down (Prepare for shutdown) message * * @throws IOException in case of an error. */ public void cancelQuietDown() throws IOException { try { client.post("/cancelQuietDown/"); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("cancelQuietDown()", e); } }
/** * Update <code>displayName</code> and the <code>description</code> of a * build. * * @param displayName The new displayName which should be set. * @param description The description which should be set. * @param crumbFlag <code>true</code> or <code>false</code>. * @throws IOException in case of errors. */ public void updateDisplayNameAndDescription(String displayName, String description, boolean crumbFlag) throws IOException { Objects.requireNonNull(displayName, "displayName is not allowed to be null."); Objects.requireNonNull(description, "description is not allowed to be null."); // TODO: Check what the "core:apply" means? ImmutableMap<String, String> params = ImmutableMap.of("displayName", displayName, "description", description, "core:apply", "", "Submit", "Save"); client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag); }
/** * Create a job on the server using the provided xml and in the provided * folder * * @param folder {@link FolderJob} * @param jobName name of the job to be created. * @param jobXml the <code>config.xml</code> which should be used to create * the job. * @param crumbFlag <code>true</code> to add <b>crumbIssuer</b> * <code>false</code> otherwise. * @throws IOException in case of an error. */ public void createJob(FolderJob folder, String jobName, String jobXml, Boolean crumbFlag) throws IOException { client.post_xml(UrlUtils.toBaseUrl(folder) + "createItem?name=" + EncodingUtils.encodeParam(jobName), jobXml, crumbFlag); }
public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxException { // We can't just put the artifact's relative path at the end of the url // string, as there could be characters that need to be escaped. URI uri = new URI(getUrl()); String artifactPath = uri.getPath() + "artifact/" + a.getRelativePath(); URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), artifactPath, "", ""); return client.getFile(artifactUri); }
/** * * @return The information from Jenkins. In cases the build has never run * {@link #BUILD_HAS_NEVER_RUN} will be returned. * @throws IOException * in case of an error. */ public BuildWithDetails details() throws IOException { return client.get(url, BuildWithDetails.class); }
/** * Restart Jenkins without waiting for any existing build to complete * * @param crumbFlag * <code>true</code> to add <b>crumbIssuer</b> <code>false</code> * otherwise. * @throws IOException * in case of an error. */ public void restart(Boolean crumbFlag) throws IOException { try { client.post("/restart", crumbFlag); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("restart()", e); } }
/** * Create a folder on the server (as a subfolder of this folder) * * @param folderName name of the folder to be created. * @param crumbFlag true/false. * @throws IOException in case of an error. */ public void createFolder(String folderName, Boolean crumbFlag) throws IOException { // https://gist.github.com/stuart-warren/7786892 was slightly helpful // here ImmutableMap<String, String> params = ImmutableMap.of("mode", "com.cloudbees.hudson.plugins.folder.Folder", "name", EncodingUtils.encodeParam(folderName), "from", "", "Submit", "OK"); client.post_form(this.getUrl() + "/createItem?", params, crumbFlag); }