【问题标题】:Return values from Powershell script into Azure devops tasks从 Powershell 脚本返回值到 Azure devops 任务
【发布时间】:2021-12-04 06:18:44
【问题描述】:

我有一个返回字符串值的 Powershell 脚本。我正在使用 AzurePowerShell 任务调用此脚本,并且我想保留返回的值以在同一管道中的后续任务中使用它。我怎样才能做到这一点?请问有什么想法吗?

   function a {
   <<processing steps>>
   return $(testString)
}

- task: AzurePowerShell@ 
  ScriptPath: Powershelltest.ps1 (calls the above powershell script)

- task: AzureCLI@
  inlineScript: | 
    use the value from $testString(??)

How can I catch the return value from Powershell in the first task (AzurePowerShell) and use it in AzureCLI task?

Thanks

 


  [1]: https://i.stack.imgur.com/Ktlaf.png

【问题讨论】:

  • 请以纯文本格式发布代码,格式正确。

标签: azure powershell azure-devops


【解决方案1】:

在您的第一个任务中使用此命令:##vso[task.setvariable variable=testString]$testString'。在您的第二个任务中,您将像这样调用变量:$(testString)。

您的函数应如下所示:

function a {
  <<processing steps>>
  ##vso[task.setvariable variable=testString]$testString'
}

如果只是想在后续步骤中使用,则不一定需要返回该值。

链接:https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#expansion-of-variables

【讨论】:

  • 我用你的 PowerShell 脚本的代码应该是什么样子更新了我的答案。如果只在其他任务中需要,则不需要返回变量值。
  • 谢谢,我已按照建议添加了该行。我向前移动了一点,撞到了另一个阻挡者。看起来 powershell 脚本没有被调用,因为它出现“模块路径未按预期在托管代理中存在”。
猜你喜欢
  • 2020-12-09
  • 2022-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-05
  • 1970-01-01
  • 2020-12-01
  • 2022-08-04
相关资源
最近更新 更多