Skip to content

Commit 4f03c11

Browse files
authored
Merge pull request #496 from joschi/aws-codebuild
Add support for AWS CodeBuild
2 parents 88de324 + 5507e96 commit 4f03c11

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of git-commit-id-plugin by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
3+
*
4+
* git-commit-id-plugin is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* git-commit-id-plugin is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with git-commit-id-plugin. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package pl.project13.core.cibuild;
19+
20+
import pl.project13.core.GitCommitPropertyConstant;
21+
import pl.project13.core.log.LoggerBridge;
22+
23+
import javax.annotation.Nonnull;
24+
import java.util.Map;
25+
import java.util.Properties;
26+
27+
public class AwsCodeBuildBuildServerData extends BuildServerDataProvider {
28+
29+
AwsCodeBuildBuildServerData(LoggerBridge log, @Nonnull Map<String, String> env) {
30+
super(log,env);
31+
}
32+
33+
/**
34+
* @see <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html">Environment variables in build environments</a>
35+
*/
36+
public static boolean isActiveServer(Map<String, String> env) {
37+
return env.containsKey("CODEBUILD_BUILD_ARN");
38+
}
39+
40+
@Override
41+
void loadBuildNumber(@Nonnull Properties properties) {
42+
String buildNumber = env.getOrDefault("CODEBUILD_BUILD_NUMBER", "");
43+
put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
44+
45+
String buildArn = env.get("CODEBUILD_BUILD_ID");
46+
put(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, buildArn);
47+
}
48+
49+
@Override
50+
public String getBuildBranch() {
51+
String environmentBasedBranch = env.getOrDefault("CODEBUILD_SOURCE_VERSION", "");
52+
log.info("Using environment variable based branch name. CODEBUILD_SOURCE_VERSION = {}", environmentBasedBranch);
53+
return environmentBasedBranch;
54+
}
55+
}

core/src/main/java/pl/project13/core/cibuild/BuildServerDataProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public static BuildServerDataProvider getBuildServerProvider(@Nonnull Map<String
106106
if (GitHubBuildServerData.isActiveServer(env)) {
107107
return new GitHubBuildServerData(log, env);
108108
}
109+
if (AwsCodeBuildBuildServerData.isActiveServer(env)) {
110+
return new AwsCodeBuildBuildServerData(log, env);
111+
}
109112
return new UnknownBuildServerData(log, env);
110113
}
111114

maven/docs/using-the-plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,6 @@ Refer to the table below to see which values are supported by which CIs.
914914

915915
| variable | description | supported CIs |
916916
| ------------------------- | ----------------------------------------|:---------------------------------------------------------:|
917-
|`git.build.number` | holds a project specific build number | Bamboo, Hudson, Jenkins, TeamCity, Travis, Gitlab CI (Gitlab >8.10 & Gitlab CI >0.5), Azure DevOps|
918-
|`git.build.number.unique` | holds a system wide unique build number | TeamCity, Travis, Gitlab CI (Gitlab >11.0) |
917+
|`git.build.number` | holds a project specific build number | Bamboo, Hudson, Jenkins, TeamCity, Travis, Gitlab CI (Gitlab >8.10 & Gitlab CI >0.5), Azure DevOps, AWS CodeBuild |
918+
|`git.build.number.unique` | holds a system wide unique build number | TeamCity, Travis, Gitlab CI (Gitlab >11.0), AWS CodeBuild |
919919

0 commit comments

Comments
 (0)