如何在Azure构建管道中使用Powershell修改过程变量 [英] How can I modify a process variable using Powershell in a Azure build pipeline

查看:125
本文介绍了如何在Azure构建管道中使用Powershell修改过程变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的管道中有一个测试"步骤.我希望该步骤在计划的运行中运行所有测试,但仅影响手动或门控运行的测试. 为此,我将runOnlyImpactedTests值链接到一个过程变量,并尝试使用Powershell修改其值.

I have a Tests step in my pipeline. I want that step to run all tests on scheduled runs but only impacted Tests on manual or gated runs. To do this, I linked the runOnlyImpactedTests value to a process variable and I'm trying to modify its value using Powershell.

我能够读取变量,但无法更改.我有两个问题,但首先,这是PS脚本

I'm able to read the variable but I can't change it. I have two questions but first, here are the PS scriptlet

Write-Host "a ${Env:Parameters_runOnlyImpactedTests} b"
Write-Host "##vso[task.setvariable variable=Parameters.runOnlyImpactedTests]True"
Write-Host "c ${Env:Parameters_runOnlyImpactedTests} d"

#Build Reasons:
#https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/ff736208(v=vs.120)

if($Env:BUILD_REASON -eq "Schedule"){
    Write-Host "Is Scheduled. Should run all tests"
    Write-Host "##vso[task.setvariable variable=Parameters.runOnlyImpactedTests]False"
}

#gci env:
#gci variable:

# Use the environment variables input below to pass secret variables to this script.

及其输出

2019-11-04T18:32:37.5783531Z Génération du script.
2019-11-04T18:32:37.6377454Z a False b
2019-11-04T18:32:37.6408504Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\BuildsVnexAgents\Agt1-3348\_work\_temp\2fca26a4-3bb5-4d51-9d90-a29aa4c755b5.ps1'"
2019-11-04T18:32:37.9377454Z c False d
2019-11-04T18:32:37.9846229Z 

我还尝试使用Parameters_runOnlyImpactedTestsEnv:Parameters_runOnlyImpactedTests设置变量,但它们都给出相同的结果.

I also tried setting the variable using Parameters_runOnlyImpactedTests and Env:Parameters_runOnlyImpactedTests but they all give the same result.

我现在有两个问题:

  1. 为什么变量不采用值
  2. 如果不能那样工作,是否有其他选择可以实现我的目标?

推荐答案

这对您有用吗?

${Env:Parameters_runOnlyImpactedTests} = $false
Write-Host "a ${Env:Parameters_runOnlyImpactedTests} b"
${Env:Parameters_runOnlyImpactedTests} = $true
Write-Host "c ${Env:Parameters_runOnlyImpactedTests} d"

输出:

2019-11-05T09:56:39.8505031Z a False b
2019-11-05T09:56:39.8513437Z c True d

${Env:Parameters_runOnlyImpactedTests}在其他管道任务中也应适用.

${Env:Parameters_runOnlyImpactedTests} should also avalible in other pipeline tasks.

这篇关于如何在Azure构建管道中使用Powershell修改过程变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆