Replies: 2 comments 1 reply
-
I don't use AzDO myself, but in GitHub Actions you have to explicitly export output variables from a job in order to consume them from another job. Is something like that possible in AzDO, perhaps? |
Beta Was this translation helpful? Give feedback.
-
Yes, you can! But you have to use a special syntax: When GitVersion runs, it creates variables that can be used by tasks running in the same job simply as So, in your case, since the job you want to access the GitVersion variable from is in a different stage from the job that created the variable, you must use this Here's a really simple pipeline that defines two stages where the first stage calculates the version using GitVersion and the second stage merely consumes a variable. ---
parameters:
- name: configFilePath
type: string
default: GitVersion.yml
stages:
- stage: versioning
displayName: Calculate Version
pool:
name: MyBuildPool
dependsOn: []
jobs:
- job: calculateVersion
displayName: Calculate Version
steps:
- checkout: self
clean: true
persistCredentials: true
fetchDepth: 0 # By default, AzureDevOps does a shallow clone, but we need full history for GitVersion
# I actually also use a template for GitVersion. I also do not use the built-in AzureDevOps task
# because in my organization, I'm unable to use it because it goes to the internet to an unapproved
# location--to get updated files. So I use the dotnet tool version instead....
# I'm going to inline my template here
- pwsh: |-
Write-Host '##[command]dotnet tool restore'
dotnet tool restore
displayName: Restore Required dotnet tools
- pwsh: |-
$ConfigFile = '${{ parameters.configFilePath }}'
Write-Host "##[command]dotnet gitversion -config "$ConfigFile" -output buildserver"
dotnet gitversion -config "$ConfigFile" -output buildserver
displayName: Calculate Version and Set Build Pipeline Variables
name: calculateVersion
- stage: consumeGitVersion
displayName: Consume GitVersion Variables
dependsOn: [versioning]
pool:
name: MyBuildPool
jobs:
- job: useGitVersion
displayName: Display Calculated Full Semver
variables:
# You MUST set a variable in this section with the stage dependency variable
GitVersion.FullSemver: $[ stageDependencies.versioning.outputs['calculateVersion.GitVersion.FullSemVer'] ]
steps:
-pwsh: |-
Write-Host "Calculated Full Semver: $(GitVersion.FullSemver)" |
Beta Was this translation helpful? Give feedback.
-
Hi
I have my azure devops pipeline like this
My
azure-pipelines-create-version-tag-template.yml
look like thisI want to access GitVersion variable
MajorMinorPatch
inside myCreateVersionTag
job.Do anyone know how I can do this or if it is even possible?
I have already tried replacing
$buildNumber
with$(GitVersion.MajorMinorPatch)
and$(GitVersion_MajorMinorPatch)
without success.I can access the variable just fine within my other template, which is where I have the
gitversion/setup@0
andgitversion/execute@0
tasks.Beta Was this translation helpful? Give feedback.
All reactions