在我的管道中有一个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任务之前让addSpnToEnvironment: true在AzureCLI任务中提供给我的。
当Powershell任务运行时,我得到了ArgumentParseError: argument --username/-u: expected one argument。我怎么解决这个问题?
发布于 2020-12-07 02:02:56
检查密码值是否使用字符'-'.启动。
这是由主要字符'-‘引起的一个已知问题,它使参数解析器将其混淆为选项名。见这里。
作为解决办法,您可以通过在选项名和值之间添加“=”来解决这个问题。
az login --service-principal --username=$env:servicePrincipalId --password=$env:servicePrincipalKey --tenant=$env:tenantId此外,您还可以尝试以下方法:
发布于 2020-12-04 22:58:38
我建议您使用Azure PowerShell任务,其中:
使用此任务在Azure环境中运行PowerShell脚本。Azure上下文通过提供的Azure资源管理器服务连接进行身份验证。
# 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 == OtherVersionhttps://stackoverflow.com/questions/65145148
复制相似问题