gpt4 book ai didi

azure - 如何从 DevOps 管道安全登录 Az CLI

转载 作者:行者123 更新时间:2023-12-04 11:51:46 26 4
gpt4 key购买 nike

我想从我的 Azure DevOps Pipeline 执行 AZ cli 命令。在我的 YAML 文件中,我有以下内容:

trigger:
- master

pool:
vmImage: 'ubuntu-latest'

variables:
buildConfiguration: 'Release'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'

# Updating pip to latest
- script: python -m pip install --upgrade pip
displayName: 'Upgrade pip'

# Updating to latest Azure CLI version.
- script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
displayName: 'upgrade azure cli'

- script: az --version
displayName: 'Show Azure CLI version'

- script: az extension add -n azure-devops
displayName: 'Install Azure DevOps Extension'

- script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
env:
AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
displayName: 'Login Azure DevOps Extension'

- script: az aks show --name census-k8s --resource-group Census
displayName: 'Show AKS'

回显 ${AZURE_DEVOPS_CLI_PAT} | az devops 登录步骤已完成(显然成功),并显示一条警告消息

Failed to store PAT using keyring; falling back to file storage.
You can clear the stored credential by running az devops logout.
Refer https://aka.ms/azure-devops-cli-auth to know more on sign in with PAT.

az aks show 步骤失败:

Please run 'az login' to setup account.

我有点迷失了。 az devops login 命令应该使我能够使用 az cli,对吗?如果没有,我是否应该使用az login而不是az devops login?如果我应该使用az登录,我如何以安全的方式传递我的凭据?

最佳答案

不,您不需要 az devops 登录。您需要的是Azure CLI Task :

- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: <Name of the Azure Resource Manager service connection>
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show

但是这样您就不必进行任何登录。请调用您的 az aks show --name census-k8s --resource-group Census

关于azure - 如何从 DevOps 管道安全登录 Az CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64502148/

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