diff --git a/Jenkinsfile b/Jenkinsfile index 06ab587..fda34da 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,7 @@ -#!groovy - -buildPlugin() - +buildPlugin( + jdkVersions: [11, 17], + useContainerAgent: true, + configurations: [ + [platform: 'linux', jdk: 17], + [platform: 'windows', jdk: 11], +]) \ No newline at end of file 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..8fb946c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,7 @@ org.jenkins-ci.plugins plugin - - 1.609.1 + 4.83 @@ -15,11 +14,11 @@ hpi - 2.5.1 - 1.112 - 2.6 2.10 - 1.11 + 2.80 + + 2.387.3 + 11 Bitbucket Build Status Notifier Plugin @@ -42,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 @@ -74,78 +73,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,8 +134,8 @@ org.jenkins-ci.tools maven-hpi-plugin - ${maven-hpi-plugin.version} true + 3.55 @@ -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,11 @@ + + com.cloudbees + maven-license-plugin + 1.17 + @@ -198,4 +181,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..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; @@ -39,26 +40,46 @@ 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) { + 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; 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; }