Skip to content

Commit 5145ee5

Browse files
AlphaYankeearturcic
authored andcommitted
Do not return the tag as branch name for GitLab CI
In case of a tag pipeline, return null as branch name instead of the tag
1 parent 0d5abd6 commit 5145ee5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/GitVersion.BuildAgents/Agents/GitLabCi.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ public override string[] GenerateSetParameterMessage(string name, string? value)
2121
$"GitVersion_{name}={value}"
2222
];
2323

24-
public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME");
24+
public override string? GetCurrentBranch(bool usingDynamicRepos)
25+
{
26+
// CI_COMMIT_REF_NAME can contain either the branch or the tag
27+
// See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
28+
29+
// CI_COMMIT_TAG is only available in tag pipelines,
30+
// so we can exit if CI_COMMIT_REF_NAME would return the tag
31+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI_COMMIT_TAG")))
32+
return null;
33+
34+
return Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME");
35+
}
2536

2637
public override bool PreventFetch() => true;
2738

0 commit comments

Comments
 (0)