Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc touch up #8

Merged
merged 5 commits into from
Oct 29, 2024
Merged
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
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
Loading