From 426f2b046b23b87114967b2faf9a14c12091271e Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Thu, 17 Sep 2026 23:26:06 +0200 Subject: [PATCH] feat(azure)!: replace dotted pipeline variable names --- BREAKING_CHANGES.md | 26 +++++ docs/input/docs/migration/v6-to-v7.md | 33 +++++++ .../reference/build-servers/azure-devops.md | 94 +++++++++++++++++++ .../Agents/AzurePipelinesTests.cs | 17 +++- .../Agents/AzurePipelines.cs | 4 +- .../Tasks/WriteVersionInfoTest.cs | 15 ++- 6 files changed, 178 insertions(+), 11 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index e9ab5f5b7f..b9d5b2c115 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -1,5 +1,29 @@ ## Unreleased +### Azure Pipelines variable names use underscores + +In v7.0, the CLI's build-server output and `GitVersion.MsBuild` emit +`GitVersion_` for both ordinary and output variables. Dotted +`GitVersion.` names are no longer emitted, and no aliases are provided. + +Update pipeline references such as `$(GitVersion.SemVer)` to +`$(GitVersion_SemVer)` and named-step references such as +`$(version.GitVersion.SemVer)` to `$(version.GitVersion_SemVer)`. Update conditions, +templates, environment mappings, log parsers, and cross-job/stage output keys +such as `outputs['version.GitVersion.SemVer']` to +`outputs['version.GitVersion_SemVer']` as well. + +The ordinary shell environment name remains `GITVERSION_SEMVER`. Check for +user-defined underscore variables that the new outputs could overwrite and +dotted variables that normalize to the same environment key. Build-number +interpolation continues to accept both dotted and underscore placeholders. + +GitTools' Azure `gitversion-execute` task already emits underscore-prefixed and +camel-case names from JSON; its output names need no separator migration for +this change. Check the task's supported GitVersion versions separately before +adopting v7. See the [v6-to-v7 migration guide][azure-variable-migration] for the +full reference mapping. + ### Pre-release output variables renamed The pre-release output variables now use SemVer label terminology consistently: @@ -341,3 +365,5 @@ work for you [system-commandline]: https://github.com/dotnet/command-line-api [configuration-migration]: https://gitversion.net/docs/reference/configuration#migrating-master-overrides-from-v5 + +[azure-variable-migration]: docs/input/docs/migration/v6-to-v7.md#azure-pipelines-variable-names diff --git a/docs/input/docs/migration/v6-to-v7.md b/docs/input/docs/migration/v6-to-v7.md index d4d20f9fe7..febb9db9f3 100644 --- a/docs/input/docs/migration/v6-to-v7.md +++ b/docs/input/docs/migration/v6-to-v7.md @@ -6,6 +6,37 @@ Description: Migration guidance for upgrading from GitVersion v6 to GitVersion v This document summarizes the relevant breaking changes when migrating from GitVersion v6 to v7. +## Azure Pipelines variable names + +The CLI's build-server output and `GitVersion.MsBuild` now emit +`GitVersion_` for both ordinary and output variables. Dotted +`GitVersion.` names are removed without aliases in v7.0. + +For a producer step named `version`, job `Build`, and stage `Compile`: + +| Consumer | v6 | v7 | +| --- | --- | --- | +| Later-step macro | `$(GitVersion.SemVer)` | `$(GitVersion_SemVer)` | +| Expression | `variables['GitVersion.SemVer']` | `variables['GitVersion_SemVer']` | +| Named-step macro | `$(version.GitVersion.SemVer)` | `$(version.GitVersion_SemVer)` | +| Dependent job | `$[ dependencies.Build.outputs['version.GitVersion.SemVer'] ]` | `$[ dependencies.Build.outputs['version.GitVersion_SemVer'] ]` | +| Dependent stage's job | `$[ stageDependencies.Compile.Build.outputs['version.GitVersion.SemVer'] ]` | `$[ stageDependencies.Compile.Build.outputs['version.GitVersion_SemVer'] ]` | + +Update conditions, templates, explicit environment mappings, and custom log +parsers as well as task inputs. Pin the previous tool version until consumers +are migrated. The ordinary shell environment name remains `GITVERSION_SEMVER`; +check for user-defined underscore variables that the new pipeline outputs could +overwrite and dotted variables that normalize to the same environment key. + +Build-number interpolation still accepts both dotted and underscore placeholders. +JSON property names, DotEnv keys, and MSBuild properties are unaffected by this +separator change. Other build agents retain their existing naming conventions. + +GitTools' Azure `gitversion-execute` task already emits underscore-prefixed and +camel-case names from JSON. Its output names need no separator migration for this +change; check the task's supported tool versions separately before adopting v7. +See [Azure DevOps][azure-devops] for complete dependency and environment examples. + ## Branch environment overrides `GIT_BRANCH` and its cross-platform alias `Git_Branch` now supply branch context at @@ -229,3 +260,5 @@ remains available to convert flat files after runtime support is removed. [git-backend]: #git-backend [version-variables]: /docs/reference/variables + +[azure-devops]: /docs/reference/build-servers/azure-devops diff --git a/docs/input/docs/reference/build-servers/azure-devops.md b/docs/input/docs/reference/build-servers/azure-devops.md index e1e0f3e035..eeaccb49f8 100644 --- a/docs/input/docs/reference/build-servers/azure-devops.md +++ b/docs/input/docs/reference/build-servers/azure-devops.md @@ -20,8 +20,102 @@ See [the Azure DevOps documentation][the-azure-devops-documentation] for more in More information can be found at [gittools/actions][gittools-actions]. +## Pipeline variables + +When the CLI runs with `--output buildserver`, or `GitVersion.MsBuild` writes +build-server output, GitVersion v7 emits `GitVersion_` as both an +ordinary variable and a named-step output variable (`isOutput=true`). For example: + +| Access from a later step | Example | +| --- | --- | +| Ordinary pipeline variable | `$(GitVersion_SemVer)` | +| Output from a step named `version` | `$(version.GitVersion_SemVer)` | +| Expression | `variables['GitVersion_SemVer']` | +| Bash environment variable | `$GITVERSION_SEMVER` | +| PowerShell environment variable | `$env:GITVERSION_SEMVER` | + +Azure uppercases variable names and converts periods to underscores when +projecting them into the environment. Pipeline names and environment names are +separate contracts. Logging commands make values available to subsequent steps; +they do not update macros or environment variables in the running producer script. +See Microsoft's [variable reference][azure-variables] and [output-variable guide][azure-outputs]. + +The GitTools `gitversion-execute` task has its own output contract: it reads JSON +and emits names such as `semVer` and `GitVersion_SemVer`. Refer to the +[task documentation][gittools-actions] for supported GitVersion versions and task +outputs; task support for v7 is separate from this CLI change. + +### Direct CLI across jobs and stages + +The following example assumes GitVersion v7 is installed on the producer agent. +The producer step must have a `name`; downstream jobs and stages must depend on +the producer. Map outputs in the consumer job's `variables` block using the full +quoted `step.variable` key. + +```yaml +stages: +- stage: Compile + jobs: + - job: Build + steps: + - checkout: self + fetchDepth: 0 + - pwsh: dotnet-gitversion --output buildserver + name: version + - pwsh: | + Write-Host "Ordinary: $(GitVersion_SemVer)" + Write-Host "Step output: $(version.GitVersion_SemVer)" + - job: Package + dependsOn: Build + variables: + packageVersion: $[ dependencies.Build.outputs['version.GitVersion_SemVer'] ] + steps: + - pwsh: | + Write-Host "Package version: $env:PACKAGE_VERSION" + env: + PACKAGE_VERSION: $(packageVersion) +- stage: Publish + dependsOn: Compile + jobs: + - job: Release + variables: + releaseVersion: $[ stageDependencies.Compile.Build.outputs['version.GitVersion_SemVer'] ] + steps: + - pwsh: | + Write-Host "Release version: $env:RELEASE_VERSION" + env: + RELEASE_VERSION: $(releaseVersion) +``` + +This example uses ordinary build jobs. Deployment and matrix jobs have additional +output-key rules; see Microsoft's [output-variable guide][azure-outputs]. + +### Upgrading from v6 + +Starting in v7, dotted pipeline names such as `GitVersion.SemVer` are no longer +emitted. Update macros, conditions, dependency output keys, reusable templates, +explicit environment mappings, and log parsers to `GitVersion_SemVer`. There are +no dotted aliases. See the [v6-to-v7 migration guide][azure-migration] for examples. + +The ordinary environment key remains `GITVERSION_SEMVER`. Remove conflicting +user-defined variables: `GitVersion.SemVer` and `GitVersion_SemVer` project to +the same environment key, and GitVersion now writes the underscore pipeline name. +When a pipeline deliberately keeps both names with different values, explicitly +map the intended pipeline variable to a distinct environment key for scripts. + +GitVersion's build-number interpolation continues to accept both +`$(GitVersion.SemVer)` and `$(GitVersion_SemVer)` placeholders. This input +compatibility does not restore dotted pipeline outputs. Disabling +`output.update-build-number` does not disable output-variable emission. + [gittools-bundle]: https://marketplace.visualstudio.com/items?itemName=gittools.gittools [the-azure-devops-documentation]: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#shallow-fetch [gittools-actions]: https://github.com/GitTools/actions/blob/main/docs/examples/azure/gitversion/index.md + +[azure-variables]: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops + +[azure-outputs]: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops + +[azure-migration]: /docs/migration/v6-to-v7#azure-pipelines-variable-names diff --git a/src/GitVersion.BuildAgents.Tests/Agents/AzurePipelinesTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/AzurePipelinesTests.cs index e63945b96e..ad425801e3 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/AzurePipelinesTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/AzurePipelinesTests.cs @@ -34,13 +34,19 @@ public void ShouldSetBuildNumber() vsVersion.ShouldBe("##vso[build.updatebuildnumber]Some Build_Value 0.0.0-Unstable4 20151310.3 $(UnknownVar) Release"); } - [Test] - public void ShouldSetOutputVariables() + [TestCase("0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'")] + [TestCase(null)] + [TestCase("")] + [TestCase("0")] + public void ShouldSetOutputVariables(string? value) { - var vsVersion = this.buildServer.SetOutputVariables("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'"); + var vsVersion = this.buildServer.SetOutputVariables("Foo", value); - vsVersion.ShouldContain("##vso[task.setvariable variable=GitVersion.Foo]0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'"); - vsVersion.ShouldContain("##vso[task.setvariable variable=GitVersion.Foo;isOutput=true]0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'"); + vsVersion.ShouldBe(new[] + { + $"##vso[task.setvariable variable=GitVersion_Foo]{value}", + $"##vso[task.setvariable variable=GitVersion_Foo;isOutput=true]{value}" + }); } [Test] @@ -70,6 +76,7 @@ public void AzurePipelinesBuildNumberWithFullSemVer(string buildNumberFormat, st [TestCase("$(GITVERSION_SEMVER)", "1.0.0", "1.0.0")] [TestCase("$(GitVersion.SemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234")] [TestCase("$(GITVERSION_SEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234")] + [TestCase("$(GitVersion.SemVer)-$(GitVersion_SemVer)", "1.0.0", "1.0.0-1.0.0")] public void AzurePipelinesBuildNumberWithSemVer(string buildNumberFormat, string mySemVer, string expectedBuildNumber) { this.environment.SetEnvironmentVariable(key, buildNumberFormat); diff --git a/src/GitVersion.BuildAgents/Agents/AzurePipelines.cs b/src/GitVersion.BuildAgents/Agents/AzurePipelines.cs index cadd2039ce..8c2f9b8c51 100644 --- a/src/GitVersion.BuildAgents/Agents/AzurePipelines.cs +++ b/src/GitVersion.BuildAgents/Agents/AzurePipelines.cs @@ -12,8 +12,8 @@ internal class AzurePipelines(IEnvironment environment, ILogger public override string[] SetOutputVariables(string name, string? value) => [ - $"##vso[task.setvariable variable=GitVersion.{name}]{value}", - $"##vso[task.setvariable variable=GitVersion.{name};isOutput=true]{value}" + $"##vso[task.setvariable variable=GitVersion_{name}]{value}", + $"##vso[task.setvariable variable=GitVersion_{name};isOutput=true]{value}" ]; public override string? GetCurrentBranch(bool usingDynamicRepos) diff --git a/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs b/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs index ec798952f0..574c30289b 100644 --- a/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs +++ b/src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs @@ -17,7 +17,7 @@ public void WriteVersionInfoTaskShouldNotLogOutputVariablesToBuildOutput() result.Success.ShouldBe(true); result.Errors.ShouldBe(0); - result.Log.ShouldNotContain("##vso[task.setvariable variable=GitVersion.FullSemVer]"); + result.Log.ShouldNotContain("##vso[task.setvariable"); } [Test] @@ -29,7 +29,9 @@ public void WriteVersionInfoTaskShouldLogOutputVariablesToBuildOutputInAzurePipe result.Success.ShouldBe(true); result.Errors.ShouldBe(0); - result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion.FullSemVer]1.0.1-1"); + result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion_FullSemVer]1.0.1-1"); + result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion_FullSemVer;isOutput=true]1.0.1-1"); + result.Log.ShouldNotContain("##vso[task.setvariable variable=GitVersion."); } [TestCase("2021-02-14.1")] @@ -47,6 +49,9 @@ public void WriteVersionInfoTaskShouldNotUpdateBuildNumberInAzurePipeline(string result.Success.ShouldBe(true); result.Errors.ShouldBe(0); result.Log.ShouldNotContain("##vso[build.updatebuildnumber]"); + result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion_FullSemVer]1.0.1-1"); + result.Log.ShouldContain("##vso[task.setvariable variable=GitVersion_FullSemVer;isOutput=true]1.0.1-1"); + result.Log.ShouldNotContain("##vso[task.setvariable variable=GitVersion."); } [TestCase("2021-02-14.1-$(GITVERSION.FullSemVer)", "2021-02-14.1-1.0.1-1")] @@ -103,7 +108,7 @@ public void WriteVersionInfoTaskShouldNotLogOutputVariablesToBuildOutputWhenRunW result.MsBuild.OverallSuccess.ShouldBe(true); result.MsBuild.ShouldAllBe(x => x.Succeeded); result.Output.ShouldNotBeNullOrWhiteSpace(); - result.Output.ShouldNotContain("##vso[task.setvariable variable=GitVersion.FullSemVer]"); + result.Output.ShouldNotContain("##vso[task.setvariable"); } [Test] @@ -119,7 +124,9 @@ public void WriteVersionInfoTaskShouldLogOutputVariablesToBuildOutputWhenRunWith result.MsBuild.OverallSuccess.ShouldBe(true); result.MsBuild.ShouldAllBe(x => x.Succeeded); result.Output.ShouldNotBeNullOrWhiteSpace(); - result.Output.ShouldContain("##vso[task.setvariable variable=GitVersion.FullSemVer]1.0.1-1"); + result.Output.ShouldContain("##vso[task.setvariable variable=GitVersion_FullSemVer]1.0.1-1"); + result.Output.ShouldContain("##vso[task.setvariable variable=GitVersion_FullSemVer;isOutput=true]1.0.1-1"); + result.Output.ShouldNotContain("##vso[task.setvariable variable=GitVersion."); } private static void AddWriteVersionInfoToBuildLogTask(ProjectCreator project, string targetToRun, string taskName)