From bae738e55cc7949d0635158a52e822e46de2d7c0 Mon Sep 17 00:00:00 2001 From: AlphaYankee <54741936+AlphaYankee@users.noreply.github.com> Date: Thu, 29 Aug 2024 23:53:18 +0200 Subject: [PATCH] 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 --- src/GitVersion.BuildAgents/Agents/GitLabCi.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/GitVersion.BuildAgents/Agents/GitLabCi.cs b/src/GitVersion.BuildAgents/Agents/GitLabCi.cs index 0956084ab7..23c0e912a1 100644 --- a/src/GitVersion.BuildAgents/Agents/GitLabCi.cs +++ b/src/GitVersion.BuildAgents/Agents/GitLabCi.cs @@ -21,7 +21,18 @@ public override string[] GenerateSetParameterMessage(string name, string? value) $"GitVersion_{name}={value}" ]; - public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME"); + public override string? GetCurrentBranch(bool usingDynamicRepos) + { + // CI_COMMIT_REF_NAME can contain either the branch or the tag + // See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html + + // CI_COMMIT_TAG is only available in tag pipelines, + // so we can exit if CI_COMMIT_REF_NAME would return the tag + if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI_COMMIT_TAG"))) + return null; + + return Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME"); + } public override bool PreventFetch() => true;