gpt4 book ai didi

azure - 在 Azure DevOps 管道中,在 powershell 任务中使用变量会导致在执行 az login 时出现 ArgumentParseError

转载 作者:行者123 更新时间:2023-12-02 07:38:33 24 4
gpt4 key购买 nike

我的管道中有一个这样的 Powershell 任务:

- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
az login --service-principal --username $env:servicePrincipalId --password $env:servicePrincipalKey --tenant $env:tenantId
python $(Build.SourcesDirectory)/the/path/to/my/python/script.py
displayName: 'Execute Python code'

在此 Powershell 任务之前,通过在 AzureCLI 任务中添加 addSpnToEnvironment: true 来向我提供服务主体详细信息。

当 Powershell 任务运行时,我得到ArgumentParseError:参数 --username/-u:需要一个参数。我该如何解决这个问题?

最佳答案

我建议您使用Azure PowerShell task其中:

Use this task to run a PowerShell script within an Azure environment. The Azure context is authenticated with the provided Azure Resource Manager service connection.

# Azure PowerShell
# Run a PowerShell script within an Azure environment
- task: AzurePowerShell@4
inputs:
#azureSubscription: Required. Name of Azure Resource Manager service connection
#scriptType: 'FilePath' # Optional. Options: filePath, inlineScript
#scriptPath: # Optional
#inline: '# You can write your Azure PowerShell scripts inline here. # You can also pass predefined and custom variables to this script using arguments' # Optional
#scriptArguments: # Optional
#errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue
#failOnStandardError: false # Optional
#azurePowerShellVersion: 'OtherVersion' # Required. Options: latestVersion, otherVersion
#preferredAzurePowerShellVersion: # Required when azurePowerShellVersion == OtherVersion

关于azure - 在 Azure DevOps 管道中,在 powershell 任务中使用变量会导致在执行 az login 时出现 ArgumentParseError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65145148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com