我已经阅读了微软官方文档并尝试了其中定义的内容。尝试了 Write-Host 和 echo 但仍然无法更新变量。
但无法实现这一点。
variables:
- name: majorVersion
value: "0"
- name: minorVersion
value: "0"
- name: patchVersion
value: "0"
- name: counterNumber
value: "0"
- name: update
value: false
jobs:
- job: Build
pool:
vmImage: 'windows-latest'
steps:
- powershell: |
echo "##vso[task.setvariable variable=update]true"
Write-Host "##vso[task.setvariable variable=majorVersion;]$versionParts[0]"
Write-Host "##vso[task.setvariable variable=minorVersion;]$versionParts[1]"
Write-Host "##vso[task.setvariable variable=patchVersion;]$patch"
请参阅此文档:在脚本中设置变量
管道中的脚本可以定义一个变量,以便管道中的后续步骤之一可以使用该变量。
当您使用命令更新 Pipeline 变量时,它不会在当前任务中起作用,但这些值可以在接下来的任务中使用。
这是更新变量并在接下来的任务中使用它的示例:
variables:
- name: majorVersion
value: "0"
- name: minorVersion
value: "0"
- name: patchVersion
value: "0"
- name: counterNumber
value: "0"
- name: update
value: false
jobs:
- job: Build
pool:
vmImage: 'windows-latest'
steps:
- powershell: |
.....
echo "##vso[task.setvariable variable=update]true"
Write-Host "##vso[task.setvariable variable=majorVersion;]$versionParts[0]"
Write-Host "##vso[task.setvariable variable=minorVersion;]$versionParts[1]"
Write-Host "##vso[task.setvariable variable=patchVersion;]$patch"
- powershell: |
echo $(update)
echo $(majorVersion)
echo $(minorVersion)
echo $(patchVersion)