Skip to content

Updated codebase to make it compile with latest versions #64

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!groovy

buildPlugin()

buildPlugin(
jdkVersions: [11, 17],
useContainerAgent: true,
configurations: [
[platform: 'linux', jdk: 17],
[platform: 'windows', jdk: 11],
])
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
79 changes: 31 additions & 48 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<!-- Baseline Jenkins version you use to build and test the plugin. Users must have this version or newer to run. -->
<version>1.609.1</version>
<version>4.83</version>
<relativePath />
</parent>

Expand All @@ -15,11 +14,11 @@
<packaging>hpi</packaging>

<properties>
<maven-release-plugin.version>2.5.1</maven-release-plugin.version>
<maven-hpi-plugin.version>1.112</maven-hpi-plugin.version>
<maven-deploy-plugin.version>2.6</maven-deploy-plugin.version>
<wagon-http.version>2.10</wagon-http.version>
<workflow.version>1.11</workflow.version>
<workflow.version>2.80</workflow.version>
<!-- Baseline Jenkins version you use to build and test the plugin. Users must have this version or newer to run. -->
<jenkins.version>2.387.3</jenkins.version>
<java.version>11</java.version>
</properties>

<name>Bitbucket Build Status Notifier Plugin</name>
Expand All @@ -42,9 +41,9 @@
</developers>

<scm>
<connection>scm:git:git://github.com/jenkinsci/bitbucket-build-status-notifier-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/bitbucket-build-status-notifier-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/bitbucket-build-status-notifier-plugin</url>
<connection>scm:git:https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin.git</connection>
<developerConnection>scm:git:https://github.com:jenkinsci/bitbucket-build-status-notifier-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin</url>
<tag>HEAD</tag>
</scm>

Expand Down Expand Up @@ -74,87 +73,69 @@
</pluginRepository>
</pluginRepositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.387.x</artifactId>
<version>2244.vd60654536b_96</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mercurial</artifactId>
<version>1.54</version>
<version>1260.vdfb_723cdcc81</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<classifier>tests</classifier>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<classifier>tests</classifier>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.3</version>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.22</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>display-url-api</artifactId>
<version>0.4</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<version>${maven-hpi-plugin.version}</version>
<extensions>true</extensions>
<version>3.55</version>
<executions>
<execution>
<goals>
Expand All @@ -166,16 +147,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin.version}</version>
<configuration>
<goals>deploy</goals>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
Expand All @@ -185,6 +163,11 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.cloudbees</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.17</version>
</plugin>
</plugins>
</build>

Expand All @@ -198,4 +181,4 @@
<url>https://repo.jenkins-ci.org/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<RemoteConfig> 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<String, URIish> getCommitRepoMap() throws Exception {
List<RemoteConfig> repoList = this.gitScm.getRepositories();
if (repoList.size() < 1) {
throw new Exception("No repos found");
}

HashMap<String, URIish> commitRepoMap = new HashMap<String, URIish>();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, URIish> getCommitRepoMap() throws Exception {
String source = this.hgSCM.getSource();
if (source == null || source.isEmpty()) {
throw new Exception("None or multiple repos");
}

HashMap<String, URIish> commitRepoMap = new HashMap<String, URIish>();
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;
}
Expand Down