我想根據 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.'
uj5u.com熱心網友回復:
為什么我的變數值沒有在 azure 管道中更新?
您可以使用VersionRevision下一個任務。
根據檔案Set variables in scripts:
當您在管道中使用 PowerShell 和 Bash 腳本時,能夠設定可以在以后的任務中使用的變數通常很有用。
這就是為什么您能夠獲取計數但無法更新變數以供進一步使用的原因,請嘗試在下一個 powershell 任務中回顯它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/495236.html
標籤:天蓝色 电源外壳 天蓝色的devops 天蓝色管道 天蓝色管道 yaml
上一篇:GitLabCI:allow_failure:exit_codes與powershell的行為不符
下一篇:客觀化Qwinsta的結果
