首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Azure DevOps管道中,在powershell任务中使用变量将导致在进行az登录时生成ArgumentParseError。

在Azure DevOps管道中,在powershell任务中使用变量将导致在进行az登录时生成ArgumentParseError。
EN

Stack Overflow用户
提问于 2020-12-04 14:14:53
回答 2查看 1.6K关注 0票数 0

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

代码语言:javascript
复制
- 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任务之前让addSpnToEnvironment: true在AzureCLI任务中提供给我的。

当Powershell任务运行时,我得到了ArgumentParseError: argument --username/-u: expected one argument。我怎么解决这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-07 02:02:56

检查密码值是否使用字符'-'.启动。

这是由主要字符'-‘引起的一个已知问题,它使参数解析器将其混淆为选项名。见这里

作为解决办法,您可以通过在选项名和值之间添加“=”来解决这个问题。

代码语言:javascript
复制
az login --service-principal --username=$env:servicePrincipalId --password=$env:servicePrincipalKey --tenant=$env:tenantId

此外,您还可以尝试以下方法:

票数 1
EN

Stack Overflow用户

发布于 2020-12-04 22:58:38

我建议您使用Azure PowerShell任务,其中:

使用此任务在Azure环境中运行PowerShell脚本。Azure上下文通过提供的Azure资源管理器服务连接进行身份验证。

代码语言:javascript
复制
# 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65145148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档