首页 > 解决方案 > AZure devops YAML 管道 Azure powershell 任务未执行

问题描述

我在 Azure DevOps YAML 管道中编写了一个 Azure PowerShell 任务,如下所示

  - task: AzurePowerShell@3
    displayName: 'Invoke Test'
    inputs:
     azureSubscription: 'subscriptionname'
     ScriptPath: '$(Build.SourcesDirectory)\ProjectName\Scripts\Build\TestRelease.ps1'
     ScriptArguments: -testfilepath '$(Build.SourcesDirectory)\ProjectName\Releases\test.json -JsonFilepath '$(Build.SourcesDirectory)\test\qa\test_qa.json' -AzuredevopsService $(AzuredevopsService) -Verbose
     azurePowerShellVersion: LatestVersion

即使管道作业成功执行,上述 PowerShell 任务也没有执行并获取如下给出的日志。当我从经典编辑器管道调用时,相同的 PowerShell 脚本正在运行

  ## Initializing Azure Complete
  ## Beginning Script Execution
  & 'C:\devops\vsts-agent-win-x64-2.154.3\_work\10\s\ProjectName\Scripts\Build\TestRelease.ps1' -testfilepath 'C:\devops\vsts-agent-win-x64-2.154.3\_work\10\s\ProjectName\Releases\test.json' -JsonFilepath 'C:\devops\vsts-agent-win-x64-2.154.3\_work\10\s\test\qa\test_qa.json' -AzuredevopsService https://test.azure.com -organisation OrgName -Verbose
 ## Script Execution Complete

标签: buildazure-devopsyamldevopsrelease

解决方案


您的 YAML 似乎有问题。请删除 中路径的单引号 (') ScriptArguments

所以,任务设置应该如下:

- task: AzurePowerShell@3
  displayName: 'Invoke Test'
  inputs:
    azureSubscription: 'subscriptionname'
    ScriptPath: '$(Build.SourcesDirectory)\ProjectName\Scripts\Build\TestRelease.ps1'
    ScriptArguments: '-testfilepath $(Build.SourcesDirectory)\ProjectName\Releases\test.json -JsonFilepath $(Build.SourcesDirectory)\test\qa\test_qa.json -AzuredevopsService $(AzuredevopsService) -Verbose'
    azurePowerShellVersion: 'LatestVersion'

如果这仍然不起作用,请尝试该任务的其他版本。例如:

- task: AzurePowerShell@5
  displayName: 'Invoke Test'
  inputs:
    azureSubscription: 'subscriptionname'
    ScriptType: 'FilePath'
    ScriptPath: '$(Build.SourcesDirectory)\ProjectName\Scripts\Build\TestRelease.ps1'
    ScriptArguments: '-testfilepath $(Build.SourcesDirectory)\ProjectName\Releases\test.json -JsonFilepath $(Build.SourcesDirectory)\test\qa\test_qa.json -AzuredevopsService $(AzuredevopsService) -Verbose'
    azurePowerShellVersion: 'LatestVersion'

推荐阅读