From 98d594a444a058a421b9649b4aa7365f3b8e38e4 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Fri, 28 Jun 2024 13:55:57 +0200 Subject: [PATCH 01/10] Upgrade plugin and remove multiple SCM changes --- README.md | 10 ++ pom.xml | 105 ++++++++++-------- .../bitbucket/api/BitbucketApiService.java | 4 +- .../plugins/bitbucket/scm/GitScmAdapter.java | 10 +- .../bitbucket/scm/MercurialScmAdapter.java | 14 +-- 5 files changed, 84 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 85ae076..c3cdf3e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,16 @@ you will be able to know when your build is passing right within the Bitbucket C Note: This plugin aims at the Atlassian-hosted BitBucket Cloud solution, not BitBucket Server (formerly known as Stash). +## Build plugin + +``` +docker run --rm -it \ + -v maven-repo:/root/.m2 \ + -v .:/usr/src/mymaven \ + -w /usr/src/mymaven \ + maven:latest mvn clean install +``` + ## Features * Notify to Bitbucket for the following build events: diff --git a/pom.xml b/pom.xml index d35773f..84889a8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,8 @@ org.jenkins-ci.plugins plugin - - 1.609.1 + + 4.46 @@ -15,11 +15,11 @@ hpi - 2.5.1 - 1.112 - 2.6 2.10 - 1.11 + 2.80 + + 2.387.3 + 8 Bitbucket Build Status Notifier Plugin @@ -74,78 +74,60 @@ + + + + io.jenkins.tools.bom + bom-2.387.x + 2244.vd60654536b_96 + import + pom + + + + org.jenkins-ci.plugins git - 2.4.0 org.jenkins-ci.plugins mercurial - 1.54 + 1260.vdfb_723cdcc81 org.jenkins-ci.plugins.workflow workflow-step-api - ${workflow.version} - - - org.jenkins-ci.plugins.workflow - workflow-cps - ${workflow.version} org.jenkins-ci.plugins.workflow workflow-job - ${workflow.version} - - - org.jenkins-ci.plugins.workflow - workflow-aggregator - ${workflow.version} - test - - - org.jenkins-ci.plugins.workflow - workflow-aggregator - tests - ${workflow.version} - test - - - org.jenkins-ci.plugins.workflow - workflow-step-api - tests - ${workflow.version} - test com.google.code.gson gson - 2.2.2 + 2.10.1 compile org.scribe scribe - 1.3.3 + 1.3.7 org.jenkins-ci.plugins credentials - 1.22 org.jenkins-ci.plugins junit - 1.0 org.jenkins-ci.plugins display-url-api - 0.4 + @@ -153,7 +135,6 @@ org.jenkins-ci.tools maven-hpi-plugin - ${maven-hpi-plugin.version} true @@ -166,16 +147,13 @@ org.apache.maven.plugins maven-release-plugin - ${maven-release-plugin.version} deploy - org.apache.maven.plugins maven-deploy-plugin - ${maven-deploy-plugin.version} org.apache.maven.wagon @@ -185,6 +163,43 @@ + + com.cloudbees + maven-license-plugin + 1.17 + + + com.github.spotbugs + spotbugs-maven-plugin + 4.7.3.0 + + + org.ow2.asm + asm + 9.5 + + + org.ow2.asm + asm-analysis + 9.5 + + + org.ow2.asm + asm-commons + 9.5 + + + org.ow2.asm + asm-tree + 9.5 + + + org.ow2.asm + asm-util + 9.5 + + + @@ -198,4 +213,4 @@ https://repo.jenkins-ci.org/snapshots - + \ No newline at end of file diff --git a/src/main/java/org/jenkinsci/plugins/bitbucket/api/BitbucketApiService.java b/src/main/java/org/jenkinsci/plugins/bitbucket/api/BitbucketApiService.java index 0573b24..953a522 100644 --- a/src/main/java/org/jenkinsci/plugins/bitbucket/api/BitbucketApiService.java +++ b/src/main/java/org/jenkinsci/plugins/bitbucket/api/BitbucketApiService.java @@ -28,6 +28,7 @@ import org.scribe.builder.api.DefaultApi20; import org.scribe.model.*; import org.scribe.oauth.OAuth20ServiceImpl; +import java.nio.charset.StandardCharsets; public class BitbucketApiService extends OAuth20ServiceImpl { @@ -60,8 +61,9 @@ public void signRequest(Token accessToken, OAuthRequest request) { private String getHttpBasicAuthHeaderValue() { String authStr = config.getApiKey() + ":" + config.getApiSecret(); + byte[] bin = authStr.getBytes(StandardCharsets.UTF_8); - return "Basic " + Base64.encodeBytes(authStr.getBytes()); + return "Basic " + Base64.encodeBytes(bin); } private String getBearerAuthHeaderValue(Token token) { diff --git a/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java b/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java index dfb313d..94b1221 100644 --- a/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java +++ b/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java @@ -39,22 +39,20 @@ public class GitScmAdapter implements ScmAdapter { private static final Logger logger = Logger.getLogger(GitScmAdapter.class.getName()); - private final GitSCM gitScm; - private final Run build; + private final BuildData buildData; + private final List repoList; public GitScmAdapter(GitSCM scm, Run build) { - this.gitScm = scm; - this.build = build; + this.repoList = scm.getRepositories(); + this.buildData = build.getAction(BuildData.class); } public Map getCommitRepoMap() throws Exception { - List repoList = this.gitScm.getRepositories(); if (repoList.size() < 1) { throw new Exception("No repos found"); } HashMap commitRepoMap = new HashMap(); - BuildData buildData = build.getAction(BuildData.class); if (buildData == null || buildData.getLastBuiltRevision() == null) { logger.warning("Build data could not be found"); } else { diff --git a/src/main/java/org/jenkinsci/plugins/bitbucket/scm/MercurialScmAdapter.java b/src/main/java/org/jenkinsci/plugins/bitbucket/scm/MercurialScmAdapter.java index 1b562e9..6ab8843 100644 --- a/src/main/java/org/jenkinsci/plugins/bitbucket/scm/MercurialScmAdapter.java +++ b/src/main/java/org/jenkinsci/plugins/bitbucket/scm/MercurialScmAdapter.java @@ -35,23 +35,23 @@ public class MercurialScmAdapter implements ScmAdapter { - private final MercurialSCM hgSCM; - private final Run build; + private final MercurialTagAction action; + private final String source; + private final String revision; public MercurialScmAdapter(MercurialSCM scm, Run build) { - this.hgSCM = scm; - this.build = build; + this.action = build.getAction(MercurialTagAction.class); + this.revision = scm.getRevision(); + this.source = scm.getSource(); } public Map getCommitRepoMap() throws Exception { - String source = this.hgSCM.getSource(); if (source == null || source.isEmpty()) { throw new Exception("None or multiple repos"); } HashMap commitRepoMap = new HashMap(); - MercurialTagAction action = build.getAction(MercurialTagAction.class); - commitRepoMap.put(action != null ? action.getId() : this.hgSCM.getRevision(), new URIish(this.hgSCM.getSource())); + commitRepoMap.put(action != null ? action.getId() : revision, new URIish(source)); return commitRepoMap; } From 0a686920755967c9d18707e1e52bde18d6aa5fd2 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Fri, 28 Jun 2024 14:09:14 +0200 Subject: [PATCH 02/10] Upgrade plugin and remove multiple SCM changes --- .../plugins/bitbucket/scm/GitScmAdapter.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java b/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java index 94b1221..410b61d 100644 --- a/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java +++ b/src/main/java/org/jenkinsci/plugins/bitbucket/scm/GitScmAdapter.java @@ -27,6 +27,7 @@ import hudson.model.Run; import hudson.plugins.git.GitSCM; import hudson.plugins.git.util.BuildData; +import hudson.plugins.git.Revision; import java.util.HashMap; import java.util.List; @@ -53,10 +54,32 @@ public Map getCommitRepoMap() throws Exception { } HashMap commitRepoMap = new HashMap(); - if (buildData == null || buildData.getLastBuiltRevision() == null) { + if (buildData == null) { logger.warning("Build data could not be found"); + + return commitRepoMap; + } + + Revision lastBuiltRevision = buildData.getLastBuiltRevision(); + if (lastBuiltRevision == null) { + logger.warning("Last build revision could not be found"); + + return commitRepoMap; + } + + RemoteConfig remoteConfig = repoList.get(0); + if (remoteConfig == null || remoteConfig.getURIs().isEmpty()) { + logger.warning("No URIs found in the remote config"); + + return commitRepoMap; + } + + URIish uri = remoteConfig.getURIs().get(0); + String sha1String = lastBuiltRevision.getSha1String(); + if (uri != null && sha1String != null) { + commitRepoMap.put(sha1String, uri); } else { - commitRepoMap.put(buildData.getLastBuiltRevision().getSha1String(), repoList.get(0).getURIs().get(0)); + logger.warning("URI or SHA1 string is null"); } return commitRepoMap; From 60d2de489a60d23d0a3464190f1b768f80452d37 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 11:10:52 +0200 Subject: [PATCH 03/10] Java 11 dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 84889a8..409c217 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 2.80 2.387.3 - 8 + 11 Bitbucket Build Status Notifier Plugin From 2b0cf7685c28647c40115854997216165850c933 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 11:16:45 +0200 Subject: [PATCH 04/10] Update jenkinsfile --- Jenkinsfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 06ab587..404299c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,7 @@ -#!groovy - -buildPlugin() - +buildPlugin( + forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores + useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests + configurations: [ + [platform: 'linux', jdk: 11], + [platform: 'windows', jdk: 11], +]) From baf837d544afc324cb5e17c19bdaa1f0377ed28d Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 11:19:40 +0200 Subject: [PATCH 05/10] Update jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 404299c..f04e164 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,6 @@ buildPlugin( forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests configurations: [ - [platform: 'linux', jdk: 11], - [platform: 'windows', jdk: 11], -]) + [platform: 'linux', jdk: 21], + [platform: 'windows', jdk: 17], +]) \ No newline at end of file From ac38ddeb12b8e8cc78c0f6a470f34b9cdadc07b3 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 11:37:15 +0200 Subject: [PATCH 06/10] Some version changes --- Jenkinsfile | 7 +++---- pom.xml | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f04e164..9d545b0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,6 @@ buildPlugin( - forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores - useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests + useContainerAgent: true, configurations: [ - [platform: 'linux', jdk: 21], - [platform: 'windows', jdk: 17], + [platform: 'linux', jdk: 17], + [platform: 'windows', jdk: 11], ]) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 409c217..b6d4af2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,7 @@ org.jenkins-ci.plugins plugin - - 4.46 + 4.53 From 0fcd185cd95365057fbfc1101dcc06697c9157c6 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 12:12:57 +0200 Subject: [PATCH 07/10] Bump jenkins-ci plugins for spotbugs --- pom.xml | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index b6d4af2..bb1cbe3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.53 + 4.80 @@ -167,38 +167,6 @@ maven-license-plugin 1.17 - - com.github.spotbugs - spotbugs-maven-plugin - 4.7.3.0 - - - org.ow2.asm - asm - 9.5 - - - org.ow2.asm - asm-analysis - 9.5 - - - org.ow2.asm - asm-commons - 9.5 - - - org.ow2.asm - asm-tree - 9.5 - - - org.ow2.asm - asm-util - 9.5 - - - From 3f01790cb58f934bbc2f12ed5e7f3ef395e0e66b Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 12:27:14 +0200 Subject: [PATCH 08/10] Minimum java version for hpi --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index bb1cbe3..f62ea7a 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,10 @@ org.jenkins-ci.tools maven-hpi-plugin true + 3.53 + + 11 + From d7b61a9e4019e78a8e7a6181ad805bb4add08ef0 Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 12:39:31 +0200 Subject: [PATCH 09/10] Buildplugin supports jdkVersions --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 9d545b0..fda34da 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ buildPlugin( + jdkVersions: [11, 17], useContainerAgent: true, configurations: [ [platform: 'linux', jdk: 17], From e2e9d0eaae82b14cbf1eb467a07dffaa0b7e5afa Mon Sep 17 00:00:00 2001 From: Davy Goossens Date: Mon, 1 Jul 2024 16:55:07 +0200 Subject: [PATCH 10/10] pom deprecation changes --- pom.xml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f62ea7a..8fb946c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.80 + 4.83 @@ -41,9 +41,9 @@ - scm:git:git://github.com/jenkinsci/bitbucket-build-status-notifier-plugin.git - scm:git:git@github.com:jenkinsci/bitbucket-build-status-notifier-plugin.git - http://github.com/jenkinsci/bitbucket-build-status-notifier-plugin + scm:git:https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin.git + scm:git:https://github.com:jenkinsci/bitbucket-build-status-notifier-plugin.git + https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin HEAD @@ -135,10 +135,7 @@ org.jenkins-ci.tools maven-hpi-plugin true - 3.53 - - 11 - + 3.55