Skip to content

Commit ebb226d

Browse files
authored
Merge pull request #449 from andrebrait/master
Add support for CircleCI
2 parents 0e98bf2 + 0292fee commit ebb226d

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ public static BuildServerDataProvider getBuildServerProvider(@Nonnull Map<String
100100
if (AzureDevOpsBuildServerData.isActiveServer(env)) {
101101
return new AzureDevOpsBuildServerData(log, env);
102102
}
103+
if (CircleCiBuildServerData.isActiveServer(env)) {
104+
return new CircleCiBuildServerData(log, env);
105+
}
103106
return new UnknownBuildServerData(log, env);
104107
}
105108

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 CircleCiBuildServerData extends BuildServerDataProvider {
28+
29+
CircleCiBuildServerData(LoggerBridge log, @Nonnull Map<String, String> env) {
30+
super(log,env);
31+
}
32+
33+
/**
34+
* @see <a href="https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables">CircleCIBuiltInVariables</a>
35+
*/
36+
public static boolean isActiveServer(Map<String, String> env) {
37+
return env.containsKey("CIRCLECI");
38+
}
39+
40+
@Override
41+
void loadBuildNumber(@Nonnull Properties properties) {
42+
String buildNumber = env.get("CIRCLE_BUILD_NUM");
43+
put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber == null ? "" : buildNumber);
44+
}
45+
46+
@Override
47+
public String getBuildBranch() {
48+
String environmentBasedBranch = env.get("CIRCLE_BRANCH");
49+
log.info("Using environment variable based branch name. CIRCLE_BRANCH = {}", environmentBasedBranch);
50+
return environmentBasedBranch;
51+
}
52+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public class GitlabBuildServerData extends BuildServerDataProvider {
3131
}
3232

3333
/**
34-
* @see <a href="https://docs.gitlab.com/ce/ci/variables/#predefined-variables-environment-variables">GitlabCIVariables</a>
34+
* @see <a href="https://docs.gitlab.com/ce/ci/variables/predefined_variables.html">GitlabCIVariables</a>
3535
*/
3636
public static boolean isActiveServer(Map<String, String> env) {
37-
return env.containsKey("CI");
37+
// CI is not unique to Gitlab CI (e.g. CircleCI). Use GITLAB_CI instead.
38+
return env.containsKey("GITLAB_CI");
3839
}
3940

4041
@Override

0 commit comments

Comments
 (0)