-
Notifications
You must be signed in to change notification settings - Fork 653
/
Copy pathTeamCity.cs
64 lines (50 loc) · 2.22 KB
/
TeamCity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using GitVersion.Helpers;
using GitVersion.OutputVariables;
using GitVersion.Logging;
namespace GitVersion.BuildServers
{
public class TeamCity : BuildServerBase
{
public TeamCity(IEnvironment environment, ILog log) : base(environment, log)
{
}
public const string EnvironmentVariableName = "TEAMCITY_VERSION";
protected override string EnvironmentVariable { get; } = EnvironmentVariableName;
public override string GetCurrentBranch(bool usingDynamicRepos)
{
var branchName = Environment.GetEnvironmentVariable("Git_Branch");
if (string.IsNullOrEmpty(branchName))
{
if (!usingDynamicRepos)
{
WriteBranchEnvVariableWarning();
}
return base.GetCurrentBranch(usingDynamicRepos);
}
return branchName;
}
private void WriteBranchEnvVariableWarning()
{
Log.Warning(@"TeamCity doesn't make the current branch available through environmental variables.
Depending on your authentication and transport setup of your git VCS root things may work. In that case, ignore this warning.
In your TeamCity build configuration, add a parameter called `env.Git_Branch` with value %teamcity.build.vcs.branch.<vcsid>%
See http://gitversion.readthedocs.org/en/latest/build-server-support/build-server/teamcity for more info");
}
public override bool PreventFetch()
{
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Git_Branch"));
}
public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
{
$"##teamcity[setParameter name='GitVersion.{name}' value='{ServiceMessageEscapeHelper.EscapeValue(value)}']",
$"##teamcity[setParameter name='system.GitVersion.{name}' value='{ServiceMessageEscapeHelper.EscapeValue(value)}']"
};
}
public override string GenerateSetVersionMessage(VersionVariables variables)
{
return $"##teamcity[buildNumber '{ServiceMessageEscapeHelper.EscapeValue(variables.FullSemVer)}']";
}
}
}