Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jenkins.version>2.375.2</jenkins.version>
<apache-httpcomponents-client-4-api.version>4.5.14-150.v7a_b_9d17134a_5</apache-httpcomponents-client-4-api.version>
</properties>

<developers>
Expand Down Expand Up @@ -88,5 +89,10 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
<version>${apache-httpcomponents-client-4-api.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -173,11 +176,11 @@ public void triggerRemoteJob(String jobTriggerUrl) {
println("[WARNING] ignoring URL exception for " + jobTriggerUrl);
}

HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
CloseableHttpClient client = HttpClients.createDefault();
HttpGet method = new HttpGet(url);
try {
client.executeMethod(method);
int statusCode = method.getStatusCode();
CloseableHttpResponse response = client.execute(method);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode < 400) {
println("Triggering " + jobUrl);
} else {
Expand All @@ -187,7 +190,11 @@ public void triggerRemoteJob(String jobTriggerUrl) {
e.printStackTrace();
println("[ERROR] Failed to trigger: " + jobUrl + " | " + e.getMessage());
} finally {
method.releaseConnection();
try {
client.close();
} catch (IOException e) {
println("[ERROR] Failed to close connection: " + jobUrl + " | " + e.getMessage());
}
}
}

Expand Down