![Azure 管道失败,如下所示:无法获取令牌 Kubernetes 任务](https://linux22.com/image/767128/Azure%20%E7%AE%A1%E9%81%93%E5%A4%B1%E8%B4%A5%EF%BC%8C%E5%A6%82%E4%B8%8B%E6%89%80%E7%A4%BA%EF%BC%9A%E6%97%A0%E6%B3%95%E8%8E%B7%E5%8F%96%E4%BB%A4%E7%89%8C%20Kubernetes%20%E4%BB%BB%E5%8A%A1.png)
我的 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 中的服务连接。