下面是我编写的变量声明和power shell脚本,用于更新队列new build
中的构建变量声明:
Power shell脚本:
$fileData = Get-Content -Path C:\builds\agent\PreviousRevisionUpdate.txt
$temp=$fileData[1]
##vso[task.setvariable variable=ActualRevision;]$temp
Write-Host "$temp - $env:ActualRevision"
输出:
2018-02-06T15:29:19.6035251Z ##[section]Starting: Actual Build Number Update
2018-02-06T15:29:19.6035251Z ==============================================================================
2018-02-06T15:29:19.6035251Z Task : PowerShell
2018-02-06T15:29:19.6035251Z Description : Run a PowerShell script
2018-02-06T15:29:19.6035251Z Version : 1.2.3
2018-02-06T15:29:19.6035251Z Author : Microsoft Corporation
2018-02-06T15:29:19.6035251Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2018-02-06T15:29:19.6035251Z ==============================================================================
2018-02-06T15:29:19.6095263Z ##[command]. 'C:\builds\agent\_work\_temp\dd262af4-0863-4f8d-a14e-1d9ea50b4c72.ps1'
2018-02-06T15:29:20.1186281Z 11 - 1
2018-02-06T15:29:20.1386321Z ##[section]Finishing: Actual Build Number Update
从上面的输出中,它仍然显示变量值为'1'而不是'11'。
下一个任务 - 更新装配信息 - >我没有得到更新的价值。
我错过了什么吗?请帮帮我。
答案 0 :(得分:2)
是的,您遗漏了一些重要内容,实际上值已更新。但是,它只能用作以下任务,而不能用于您更新的任务,这就是您的powershell脚本输出仍然显示变量值为“1”而不是“11”的原因。
在taskcontext的变量服务中设置变量。第一项任务 可以设置变量,以下任务都可以使用 变量。变量作为以下任务暴露给以下任务 环境变量。
来源链接:Logging Commands
对于测试,您可以在更新构建变量的任务之后添加powershell脚本,如下所示:
Write-Host "After: - $env:ActualRevision"
从您可以看到的结果中,ActualRevision
的值在以下任务中已更改为11。
<强>更新强>
我的剧本:
$temp=11
Write-Host "Before: $temp - $env:ActualRevision"
Write-Host ##vso[task.setvariable variable=ActualRevision;]$temp
Write-Host "After: $temp - $env:ActualRevision"
测试脚本(另一项任务):
Write-Host "After: - $env:ActualRevision"
答案 1 :(得分:1)
你应该可以使用:$ env:ActualRevision = $ temp
Powershell脚本
$temp=123
Write-Host "Before: $temp - $env:ActualRevision"
$env:ActualRevision = $temp
Write-Host "After: $temp - $env:ActualRevision"
VSTS输出
Task : PowerShell
Description : Run a PowerShell script
Version : 1.2.3
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
. 'D:\a\1\s\test.ps1'
Before: 123 - 2
After: 123 - 123
答案 2 :(得分:0)
您需要输出任务日志记录命令。所以powershell脚本的代码应该是:
Write-Host "##vso[task.setvariable variable=ActualRevision;]$temp"
然后你可以在以下任务中使用它。