为什么我的变量值没有在azure管道中更新?



我想根据git repo中的提交数量更新一个变量。我能够正确地获取计数,但无法更新变量以供进一步使用。你知道哪里出错了吗?

variables:
# Versioning
# Version Format - 'VersionMajor.VersionMinor.VersionRelease.Revision'
# Currently the Major, Minor and Minor are all constants
- name: VersionMajorMinorRelease
value: '1.0.1'

# Revision will be calculated during pipeline run based on total commit counts for branch
- name: VersionRevision
value: ''

进一步在工作中,我使用变量

- task: PowerShell@2
displayName: Set the build version
condition: eq('${{ parameters.Action }}', 'BuildAndDeploy')
inputs:
targetType: inline
script: |
$commitCounts= $(git rev-list --count HEAD)
$revision= $commitCounts.ToString()
Write-Host "Revision = '$revision'"
Write-Host "##vso[task.setvariable variable=VersionRevision]$revision"
Write-Host "Version of App being built = '$(VersionMajorMinorRelease).$(VersionRevision)'"

输出-

Revision = '1660'
Version of App being built = '1.0.1.'

为什么我的变量值没有在azure管道中更新?

你可以在下一个任务中使用VersionRevision

根据文档设置脚本变量:

当您在管道中使用PowerShell和Bash脚本时,它通常是能够设置可以在将来使用的变量是很有用的任务.

这就是为什么你可以获取计数,但不能更新变量以供进一步使用的原因,请尝试在下一个powershell任务中回显它。

最新更新