gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:20:29 38 4
gpt4 key购买 nike

我想根据 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.'

最佳答案

Why is my variable value not getting updated in azure pipeline?

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

根据文档Set variables in scripts :

When you use PowerShell and Bash scripts in your pipelines, it's oftenuseful to be able to set variables that you can then use in futuretasks.

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

关于azure - 为什么我的变量值没有在 azure 管道中更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72697182/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com