Skip to content

[ISSUE]: Provide the ability to use environment variables in labels #4745

@W0GER

Description

@W0GER

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

gittools/actions

GitVersion version

6

Operating system

macOS

What are you seeing?

GitVersion supports "{group-name}" style placeholders in labels via regex named groups. This works great for my team EXCEPT on pull requests. The label is limited to regular expression matching of the merge branch name (eg. refs/pull/68/head)

My team would really like to have the pull request source name (eg github.head_ref) available to place in the version label. This makes our version more readable when the team has several PR's in the same repository.

What is expected?

Plan: Support environment variables in GitVersion Labels

Current State

  • GitVersion supports {regex-group-name} placeholders in labels via regex named groups.
  • {env:VARIABLE_NAME} is supported in format strings (e.g., AssemblyInformationalFormat) via FormatWith.
  • Labels are processed in GetBranchSpecificLabel in ConfigurationExtensions.cs, which only handles regex placeholders.
  • IEnvironment is available in VariableProvider but not in label processing.

Solution Approach
Extend GetBranchSpecificLabel to also process {env:...} placeholders (e.g., {env:GITHUB_HEAD_REF}) after regex processing, using the existing FormatWith logic.

Steps to Reproduce

GitVersion only supports {regex-group-name} placeholders in labels via regex named groups.
Unable to add branch name workflows running on a pull request.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions