Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -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_<Property>` for both ordinary and output variables. Dotted
`GitVersion.<Property>` 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:
Expand Down Expand Up @@ -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
33 changes: 33 additions & 0 deletions docs/input/docs/migration/v6-to-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<Property>` for both ordinary and output variables. Dotted
`GitVersion.<Property>` 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
Expand Down Expand Up @@ -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
94 changes: 94 additions & 0 deletions docs/input/docs/reference/build-servers/azure-devops.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<Property>` 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
17 changes: 12 additions & 5 deletions src/GitVersion.BuildAgents.Tests/Agents/AzurePipelinesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.BuildAgents/Agents/AzurePipelines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ internal class AzurePipelines(IEnvironment environment, ILogger<AzurePipelines>

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)
Expand Down
15 changes: 11 additions & 4 deletions src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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")]
Expand All @@ -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")]
Expand Down Expand Up @@ -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]
Expand All @@ -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)
Expand Down
Loading