[英]passing pipeline variable as argument into Powershell build step not working in Azure DevOps
I want to be able to pass a pipeline variable into a Powershell build step in Azure DevOps Server.我希望能够将管道变量传递到 Azure DevOps 服务器中的 Powershell 构建步骤中。 I'm trying to accomplish this by passing the variable as an argument.
我试图通过将变量作为参数传递来实现这一点。
Here is my pipeline YAML file:这是我的管道 YAML 文件:
- task: PowerShell@2
displayName: 'Detect Subfolder Changes'
name: setvarStep
inputs:
targetType: 'filePath'
filePath: $(System.DefaultWorkingDirectory)\detectchanges.ps1
failOnStderr: true
- task: PowerShell@2
displayName: 'Get Version Number'
name: getVersion
inputs:
arguments: >
- packagepath $(setvarStep.changedPackage)
targetType: 'filePath'
filePath: $(System.DefaultWorkingDirectory)\getversion.ps1
failOnStderr: true
Here is the Powershell script (getversion.ps1) where I pass the 'packagepath' argument:这是 Powershell 脚本 (getversion.ps1),我在其中传递了“packagepath”参数:
param($packagepath)
Write-Host "packagepath is: $packagepath"
$xml = [Xml] (Get-Content $packagepath)
$version = [Version] $xml.Project.PropertyGroup.Version
"##vso[task.setvariable variable=packageVersion;isOutput=true]$version"
The Writ-Host command prints out 'packagepath is: -'. Writ-Host 命令打印出 'packagepath is: -'。 I turned on debugging and the argument value does show up in the log as:
##[debug]INPUT_ARGUMENTS: '- packagepath dotnet/TestPackage/*.csproj'
我打开了调试,参数值在日志中显示为:
##[debug]INPUT_ARGUMENTS: '- packagepath dotnet/TestPackage/*.csproj'
Instead of passing the variable as an argument I also tried inserting the variable into the script like this: $packagepath = $($env:SETVARSTEP.CHANGEDPACKAGE)
but it didn't work.除了将变量作为参数传递之外,我还尝试将变量插入到脚本中,如下所示:
$packagepath = $($env:SETVARSTEP.CHANGEDPACKAGE)
但它不起作用。
I did try adding double quotes to the argument parameter in the build step like this: - packagepath "$(setvarStep.changedPackage)"
.我确实尝试在构建步骤中为参数参数添加双引号,如下所示:
- packagepath "$(setvarStep.changedPackage)"
。 It didn't work either.它也没有用。
The argument value is getting to the Powershell script, getversion.ps1 but for some reason the value is not displaying.参数值正在获取 Powershell 脚本 getversion.ps1 但由于某种原因该值未显示。
@g.sulman Thanks for the suggestion. @g.sulman 感谢您的建议。 I changed - packagepath to -packagepath and it worked.
我将 -packagepath 更改为 -packagepath 并且它有效。 I figured it was something small like the syntax.
我认为它像语法一样小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.