Azure CLI 运行命令调用 RunPowerShellScript - 传递给脚本文件的参数被忽略

如何解决Azure CLI 运行命令调用 RunPowerShellScript - 传递给脚本文件的参数被忽略

我正在尝试从 AzDO YAML 构建管道调用“az vm run-command invoke --command-id RunPowerShellScript ...”,但无法获取参数以成功传递到 Powershell 脚本文件

还有其他与此类似的 SO 问题,尤其是这似乎具有我需要的答案的问题,但它对我不起作用:Azure CLI run-command invoke RunPowerShellScript with parameters。 我还可以从 this answer 看到参数不能是布尔类型,由此我假设除“字符串”之外的任何类型也是不允许的,但是我在 ps1 文件输入参数上添加了字符串类型属性这并不能解决我的问题。

实际行为 脚本本身确实执行,但无论我尝试以何种方式传递参数,它们始终被忽略。我可以看到记录到标准输出的值是脚本文件中参数设置的认值:$matchServiceNamePattern 设置为 'defaultservicename' 和 $maxnumberOfTries 设置为“10” - 即不是传入的值.不为参数指定认值没有任何区别,但对我的用例来说不是很安全。

预期行为 我希望我通过 YAML 文件中 Azure CLI 命令中的“--parameters matchServiceNamePattern=servicename maxnumberOfTries=25”开关传入的参数传递给脚本。

设置

  • 代理操作系统:Windows
  • 目标虚拟机操作系统:Windows
  • 脚本语言:Powershell
  • 脚本位置:作为 VM 上的本地文件引用,而非内联

我的代码的相关部分是(下面的 YAML 显示了以我认为应该根据其他 SO 答案工作的方式传递的参数):

AzureCLI YAML 管道任务:

- task: AzureCLI@2
    inputs:
      azureSubscription: $(AZURE_SUBSCRIPTION_NAME)
      scriptType: ps
      scriptLocation: inlinescript
      inlinescript: |
        az vm run-command invoke --command-id RunPowerShellScript -g $(AZURE_RESOURCE_GROUP_NAME) -n $(AZURE_VM_NAME) --scripts C:\check_service_running.ps1 --parameters matchServiceNamePattern=servicename maxnumberOfTries=25

check_service_running.ps1 Powershell 脚本文件

param (
[string]
$matchServiceNamePattern = 'defaultservicename',[string]
$maxnumberOfTries = "10")

$matchServiceNamePatternWildcard = $matchServiceNamePattern + '*'
$maxnumberOfTriesAsInt = [int]$maxnumberOfTries
$maxRepeat = $maxnumberOfTriesAsInt
$currentIteration = 1

do
{
    $matchingServices = Get-Service $matchServiceNamePatternWildcard
    $matchingServicesCount = ($matchingServices).count
    $runningServiceCount = ($matchingServices | ? {$_.status -eq "Running"}).count
    $difference = $matchingServicesCount - $runningServiceCount
    
    Write-Host "Checking to see if Service(s) matching '$matchServiceNamePatternWildcard' are all in a Running state. `
    Total service count: $matchingServicesCount,Running service count: $runningServiceCount. `
    Iteration $currentIteration of $maxnumberOfTries"
    
    $maxRepeat--
    $currentIteration++
    Start-Sleep -Milliseconds 6000
} until (($difference -le 0) -or $maxRepeat -eq 0)

Write-Host "Service running check complete."

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?