Skip to content

Commit 6ad23e1

Browse files
committed
Merge branch 'master' into feature/cake.addin
2 parents defaba8 + ddc9486 commit 6ad23e1

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

doc/cloudbuild.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ in MSBuild, gulp and other build scripts.
1414
## Optional features
1515

1616
By specifying certain `cloudBuild` options in your `version.json` file,
17-
you can activate features for some cloud build systems, as follows
17+
you can activate features for some cloud build systems, as follows:
1818

1919
### Automatically match cloud build numbers to to your git version
2020

@@ -77,6 +77,39 @@ in your `version.json` file to `true`, as shown below:
7777
}
7878
```
7979

80+
There are many more MSBuild variables that the build will set within the build. To make *all* these available as cloud variables (prefixed with `NBGV_`), you can set the `cloudBuild.setAllVariables` field to `true`:
81+
82+
```json
83+
{
84+
"version": "1.0",
85+
"cloudBuild": {
86+
"setVersionVariables": true,
87+
"setAllVariables": true
88+
}
89+
}
90+
```
91+
92+
Setting both of these fields to `true` means that a few variables will be defined in the cloud build server twice -- one set with the names in the table above and the other (full) set using the `NBGV_` prefix.
93+
94+
### Set cloud build variables from just one project
95+
96+
While each individual MSBuild project has its own version computed, the versions across projects are usually the same so long as you have one `version.json` file at the root of your repo. If you choose to enable setting of cloud build variables in that root version.json file, each project that builds will take a turn setting those cloud build variables. This is perhaps more work than is necessary, and when some projects compute versions differently it can lead to inconsistently defined cloud build variables, based on non-deterministic build ordering of your projects.
97+
98+
You can reduce log message noise and control for non-deterministic cloud build variables by *not* setting any of the `cloudBuild` options in your root version.json file, and instead defining an additional `version.json` file inside just *one* project directory that inherits from the base one, like this:
99+
100+
```json
101+
{
102+
"inherit": true,
103+
"cloudBuild": {
104+
"buildNumber": {
105+
"enabled": true
106+
},
107+
"setVersionVariables": true,
108+
"setAllVariables": true
109+
}
110+
}
111+
```
112+
80113
## CI Server specific configurations
81114

82115
### TeamCity

src/NerdBank.GitVersioning/CloudBuild.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class CloudBuild
1818
new TeamCity(),
1919
new AtlassianBamboo(),
2020
new Jenkins(),
21+
new GitLab(),
2122
};
2223

2324
/// <summary>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Nerdbank.GitVersioning.CloudBuildServices
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Diagnostics;
7+
using System.IO;
8+
9+
/// <summary>
10+
///
11+
/// </summary>
12+
/// <remarks>
13+
/// The GitLab-specific properties referenced here are documented here:
14+
/// https://docs.gitlab.com/ce/ci/variables/README.html
15+
/// </remarks>
16+
internal class GitLab : ICloudBuild
17+
{
18+
public string BuildingBranch => Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME");
19+
20+
public string BuildingRef => Environment.GetEnvironmentVariable("CI_COMMIT_TAG");
21+
22+
public string BuildingTag => Environment.GetEnvironmentVariable("CI_COMMIT_TAG");
23+
24+
public string GitCommitId => Environment.GetEnvironmentVariable("CI_COMMIT_SHA");
25+
26+
public bool IsApplicable => !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITLAB_CI"));
27+
28+
public bool IsPullRequest => false;
29+
30+
public IReadOnlyDictionary<string, string> SetCloudBuildNumber(string buildNumber, TextWriter stdout, TextWriter stderr)
31+
{
32+
return new Dictionary<string, string>();
33+
}
34+
35+
public IReadOnlyDictionary<string, string> SetCloudBuildVariable(string name, string value, TextWriter stdout, TextWriter stderr)
36+
{
37+
return new Dictionary<string, string>();
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)