我的 Azure 管道中的一个阶段失败,出现以下错误“无法获取令牌:无法获取新令牌:等待设备代码认证完成:autorest/adal/devicetoken:检索 OAuth 令牌时出错:代码已过期”
非常感谢您的帮助
2021-06-02T03:52:26.1806927Z ##[section]Starting: Deploy App in Development Enviroment
2021-06-02T03:52:26.1814528Z ==============================================================================
2021-06-02T03:52:26.1814830Z Task : Kubectl
2021-06-02T03:52:26.1815178Z Description : Deploy, configure, update a Kubernetes cluster in Azure Container Service by running kubectl commands
2021-06-02T03:52:26.1815494Z Version : 1.181.0
2021-06-02T03:52:26.1815734Z Author : Microsoft Corporation
2021-06-02T03:52:26.1816020Z Help : https://aka.ms/azpipes-kubectl-tsg
2021-06-02T03:52:26.1816326Z ==============================================================================
2021-06-02T03:52:26.8916342Z Prepending PATH environment variable with directory: /usr/local/bin
2021-06-02T04:07:29.8005355Z ==============================================================================
2021-06-02T04:07:29.8006774Z Kubectl Client Version: v1.20.4
2021-06-02T04:07:29.8007651Z Kubectl Server Version: Could not find kubectl server version
2021-06-02T04:07:29.8008688Z ==============================================================================
2021-06-02T04:07:29.9178413Z [command]/usr/local/bin/kubectl apply -f /home/myagent-agent/-dev.yaml -o json
2021-06-02T04:07:30.1210223Z To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code DZCGH5TCR to authenticate.
2021-06-02T04:22:32.1314128Z E0602 04:22:32.130844 14171 azure.go:154] Failed to acquire a token: failed acquiring new token: waiting for device code authentication to complete: autorest/adal/devicetoken: Error while retrieving OAuth token: Code Expired
2021-06-02T04:22:32.1320836Z Unable to connect to the server: acquiring a token for authorization header: failed acquiring new token: waiting for device code authentication to complete: autorest/adal/devicetoken: Error while retrieving OAuth token: Code Expired (Client.Timeout exceeded while awaiting headers)
2021-06-02T04:22:32.1410766Z ##[error]To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code DZCGH5TCR to authenticate.
2021-06-02T04:22:32.1428397Z ##[error]E0602 04:22:32.130844 14171 azure.go:154] Failed to acquire a token: failed acquiring new token: waiting for device code authentication to complete: autorest/adal/devicetoken: Error while retrieving OAuth token: Code Expired
2021-06-02T04:22:32.1431654Z ##[error]Unable to connect to the server: acquiring a token for authorization header: failed acquiring new token: waiting for device code authentication to complete: autorest/adal/devicetoken: Error while retrieving OAuth token: Code Expired (Client.Timeout exceeded while awaiting headers)
2021-06-02T04:22:32.1433510Z commandOutput
2021-06-02T04:49:16.9152434Z ##[error]The operation was canceled.
2021-06-02T04:49:16.9158969Z ##[section]Finishing: Deploy App in Development Enviroment
答案1
看起来您在 AKS 群集上设置了 Azure AD 集成,但 Kubernetes 任务无法处理此问题。您需要在 Kubernetes 中创建一个服务帐户,并将其设置为 Azure DevOps 中的服务连接。