简体   繁体   English

将管道变量作为参数传递到 Powershell 构建步骤在 Azure DevOps 中不起作用

[英]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.

相关问题 将 Azure Powershell 变量分配给 DevOps 管道变量 - Assign Azure Powershell variable to DevOps Pipeline variable 在运行 Powershell 脚本的 Azure DevOps 管道中传递脚本参数 - Pass a script argument in Azure DevOps pipeline which runs a Powershell script 如何在 Azure DevOps PowerShell Pipeline 任务中添加带下划线的参数值 - How to add argument values with underscore in Azure DevOps PowerShell Pipeline task Powershell 从 azure devops build pipeline 获取组件治理结果 - Powershell to fetch the Component Governance result from azure devops build pipeline Azure DevOps Powershell 获取与构建管道相关的工作项 - Azure DevOps Powershell get work item related to build pipeline Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? PowerShell Hashtable 作为 Azure Devops YAML 管道 Z78E6221F6393D1356681DB398F14CE6 - PowerShell Hashtable as Azure Devops YAML Pipeline output Variable Azure Devops 管道 - 如何将变量传递到 Powershell function - Azure Devops Pipeline - How to pass variable into Powershell function 如何在 Azure Devops 发布管道中使用 PowerShell 设置环境变量? - How to set an environment variable with PowerShell in Azure Devops release pipeline? Azure devOps管道中的Powershell脚本 - Powershell script in azure devOps pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM