Skip to content

Commit

Permalink
Merge pull request #8 from launchableinc/misc-touch
Browse files Browse the repository at this point in the history
Misc touch up
  • Loading branch information
kohsuke authored Oct 29, 2024
2 parents cfc93e0 + a520ea7 commit 9412d8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<defaultPort>8081</defaultPort>
<systemProperties>
<INSIGHT_UPLOAD_URL>http://localhost:8080</INSIGHT_UPLOAD_URL>
</systemProperties>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/io/jenkins/plugins/launchable/Ingester.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
Expand All @@ -25,6 +24,10 @@
public class Ingester extends GlobalConfiguration {
private Secret apiKey;

public Ingester() {
load();
}

public Secret getApiKey() {
return apiKey;
}
Expand Down Expand Up @@ -55,7 +58,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
// attempted to use JDK HttpRequest, but gave up due to the lack of multipart support
// TODO: how do I obtain a properly configured HttpClient for the proxy setting in Jenkins?
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String endpoint = System.getenv("INSIGHT_UPLOAD_URL") ;
String endpoint = System.getProperty("INSIGHT_UPLOAD_URL") ;

if (endpoint==null) {
endpoint = DEFAULT_UPLOAD_URL;
Expand All @@ -68,7 +71,6 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti

hc.setEntity(new GzipCompressingEntity(builder.build()));
hc.addHeader("Authorization", "Bearer " + apiKey.getPlainText());
hc.setHeader(HttpHeaders.CONTENT_ENCODING, "gzip");

try (CloseableHttpResponse response = httpClient.execute(hc)) {
if (response.getStatusLine().getStatusCode() >= 300) {
Expand All @@ -78,7 +80,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
}
}
}
} catch (IOException e) {
} catch (Exception e) {
// don't let our bug get in the way of orderly execution of jobs, as that'd be the fasest way to
// get kicked out of installations.
LOGGER.log(Level.WARNING, "Failed to submit test results", e);
Expand Down

0 comments on commit 9412d8b

Please sign in to comment.