forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTeamCity.cs
61 lines (48 loc) · 2.17 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
namespace GitVersion
{
using System;
public class TeamCity : BuildServerBase
{
public const string EnvironmentVariableName = "TEAMCITY_VERSION";
public override bool CanApplyToCurrentContext()
{
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(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;
}
static void WriteBranchEnvVariableWarning()
{
Logger.WriteWarning(@"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[]
{
string.Format("##teamcity[setParameter name='GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value)),
string.Format("##teamcity[setParameter name='system.GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value))
};
}
public override string GenerateSetVersionMessage(VersionVariables variables)
{
return string.Format("##teamcity[buildNumber '{0}']", ServiceMessageEscapeHelper.EscapeValue(variables.FullSemVer));
}
}
}