【问题标题】:How to identify/Fail the Azure Devops pipeline with kubernetes如何使用 kubernetes 识别/失败 Azure Devops 管道
【发布时间】:2022-11-28 15:39:06
【问题描述】:

我正在使用 Azure devops 将服务部署到 AKS。在极少数情况下,即使 Pod 未启动(处于崩溃状态),管道仍显示为成功。

我添加此任务以验证 kubectl pod:

- task: Kubernetes@1
            displayName: 'Deploy ${{ parameters.project_display_name }} to ${{ parameters.cluster }}'
            inputs:
              connectionType: Kubernetes Service Connection
              kubernetesServiceEndpoint: ${{ parameters.cluster }}-${{ parameters.namespace }}
              command: apply
              arguments: -f $(System.ArtifactsDirectory)/k8_manifest/manifest.yml -n ${{ parameters.namespace }}
              outputFormat: 'yaml'

          - task: AzureCLI@2
            displayName: 'Validate Deployment of ${{ parameters.project_display_name }} to ${{ parameters.cluster }}'
            inputs:
              scriptType: 'pscore'
              scriptLocation: 'inlineScript'
              inlineScript: |
                containerStatuses=$(kubectl get deployment loss-limit-api --namespace betting -o=jsonpath='{$.status.conditions}')
                for row in $(echo "${containerStatuses}" | jq -r '.[] | @base64'); do
                    _jq() {
                    echo ${row} | base64 --decode | jq -r ${1}
                    }
                    if [ $(_jq '.status') != "True" ]; then
                        echo "Inactive Pod erron on the deployment"
                        exit 1
                    fi
                done

它返回和错误:

Starting: Validate Deployment of Loss Limit API to core-dev00
==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version      : 2.208.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
##[error]Script failed with error: Error: Unable to locate executable file: 'pwsh'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
Finishing: Validate Deployment of Loss Limit API to core-dev00

【问题讨论】:

    标签: kubernetes azure-devops azure-pipelines azure-aks kubernetes-pod


    【解决方案1】:

    错误消息表明您的代理没有安装 PowerShell Core。要解决此问题:

    方法一:在 Azure CLI 任务中,将 batch 用作 scriptType 而不是 pscore

    方法二:在您的代理计算机上安装 PowerShell Core。详细信息可以参考this document

    使用 Microsoft 托管的 linux 代理也是一种选择。但我不推荐它,因为它可能会导致其他问题,例如无法找到托管在您机器上的文件等。

    【讨论】:

      猜你喜欢
      • 2021-07-28
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 2020-03-15
      • 2020-05-13
      相关资源
      最近更新 更多