From ae9f49152ef726dedea1ba5ce29517979ada7e51 Mon Sep 17 00:00:00 2001 From: Daniel Fly Date: Thu, 22 Jun 2017 13:46:44 +0200 Subject: Improved logging for thoubleshooting --- .../bitbucketpullrequestbuilder/bitbucket/ApiClient.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java index cb14908..cf3675c 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java @@ -256,8 +256,12 @@ public class ApiClient { client.getState().setCredentials(AuthScope.ANY, credentials); client.getParams().setAuthenticationPreemptive(true); try { - client.executeMethod(req); - return req.getResponseBodyAsString(); + int statusCode = client.executeMethod(req); + if (statusCode != HttpStatus.SC_OK) { + logger.log(Level.WARNING, "Response code failed: " + req.getStatusLine()); + }else{ + return req.getResponseBodyAsString(); + } } catch (HttpException e) { logger.log(Level.WARNING, "Failed to send request.", e); } catch (IOException e) { -- cgit v1.2.3 From 8d499a6049f88f77f2676c5dbef70c46d37948e9 Mon Sep 17 00:00:00 2001 From: Daniel Fly Date: Mon, 26 Jun 2017 09:55:57 +0200 Subject: Added missing init to fix NullPointerException when setting build status --- pom.xml | 2 +- .../bitbucketpullrequestbuilder/BitbucketBuilds.java | 1 + .../bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/pom.xml b/pom.xml index f204feb..4dc11a7 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket-pullrequest-builder Bitbucket Pullrequest Builder Plugin - 1.4.26-SNAPSHOT + 1.4.26-SNAPSHOT-sazo This Jenkins plugin builds pull requests from Bitbucket.org and will report the test results. hpi https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+pullrequest+builder+plugin diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java index 216287d..6ba3dab 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java @@ -19,6 +19,7 @@ public class BitbucketBuilds { public BitbucketBuilds(BitbucketBuildTrigger trigger, BitbucketRepository repository) { this.trigger = trigger; this.repository = repository; + this.repository.init(); } void onStarted(BitbucketCause cause, Run build) { diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java index 4474581..086cf01 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java @@ -33,7 +33,6 @@ public class BitbucketPullRequestsBuilder { public void run() { logger.fine("Build Start."); - this.repository.init(); Collection targetPullRequests = this.repository.getTargetPullRequests(); this.repository.addFutureBuildTasks(targetPullRequests); } @@ -43,6 +42,7 @@ public class BitbucketPullRequestsBuilder { throw new IllegalStateException(); } this.repository = new BitbucketRepository(this.trigger.getProjectPath(), this); + this.repository.init(); this.builds = new BitbucketBuilds(this.trigger, this.repository); return this; } -- cgit v1.2.3 From 1169c952a49d5b2d4260863397b2055893e7a11b Mon Sep 17 00:00:00 2001 From: Daniel Fly Date: Mon, 26 Jun 2017 10:00:01 +0200 Subject: Fixed missing init --- .../bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java index 086cf01..5b37fea 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java @@ -33,6 +33,7 @@ public class BitbucketPullRequestsBuilder { public void run() { logger.fine("Build Start."); + this.repository.init(); Collection targetPullRequests = this.repository.getTargetPullRequests(); this.repository.addFutureBuildTasks(targetPullRequests); } -- cgit v1.2.3 From ee9994e91c5aad01c754250c16b890b583d3b8b2 Mon Sep 17 00:00:00 2001 From: Daniel Fly Date: Mon, 26 Jun 2017 13:59:50 +0200 Subject: Fixed NPE --- .../bitbucketpullrequestbuilder/bitbucket/ApiClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java index cf3675c..0c21806 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java @@ -142,7 +142,8 @@ public class ApiClient { public boolean hasBuildStatus(String owner, String repositoryName, String revision, String keyEx) { String url = v2(owner, repositoryName, "/commit/" + revision + "/statuses/build/" + this.computeAPIKey(keyEx)); - return get(url).contains("\"state\""); + String reqBody = get(url); + return reqBody != null && reqBody.contains("\"state\""); } public void setBuildStatus(String owner, String repositoryName, String revision, BuildState state, String buildUrl, String comment, String keyEx) { @@ -258,7 +259,7 @@ public class ApiClient { try { int statusCode = client.executeMethod(req); if (statusCode != HttpStatus.SC_OK) { - logger.log(Level.WARNING, "Response code failed: " + req.getStatusLine()); + logger.log(Level.WARNING, "Response status: " + req.getStatusLine()+" URI: "+req.getURI()); }else{ return req.getResponseBodyAsString(); } -- cgit v1.2.3