Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not return the tag as branch name for GitLab CI #4187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/GitVersion.BuildAgents/Agents/GitLabCi.cs
Original file line number Diff line number Diff line change
@@ -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;