【问题标题】:How to pass the output from kubectl task to next task in Azure Devops如何将 kubectl 任务的输出传递到 Azure Devops 中的下一个任务
【发布时间】:2020-12-15 17:55:43
【问题描述】:

我正在使用 AKS。我正在尝试通过 devops 获取部署后服务的 IP,以便我可以将 IP 传递给 API 管理以进行进一步配置。现在我的任务是这样的

               - task: Kubernetes@1
                  inputs:
                    connectionType: 'Kubernetes Service Connection'
                    kubernetesServiceEndpoint: 'string-Conn'
                    namespace: '<appservices>'
                    command: 'get'
                    arguments: 'get services --namespace appservices authsvc --output jsonpath=''{.status.loadBalancer.ingress[0].ip}'''
                    secretType: 'dockerRegistry'
                    containerRegistryType: 'Azure Container Registry'
                  name: 'GetSvc'

当我在本地运行命令时,我得到了负载均衡器的 IP。但是我怎样才能将这个任务的输出传递给下一个任务呢?以前,当我使用 azure cli 脚本时,我可以将 vso set 变量作为脚本本身的一部分传递,如下所示,但不确定如何将此任务的输出添加到变量中。

内联脚本:|

$something = (az storage container generate-sas --account-name <container> --name armtemplate --permissions r --expiry $(date -u -d "30 minutes" +%Y-%m-%dT%H:%MZ))
                  Write-Host($something) Write-Output("##vso[task.setvariable variable=SasToken;]$something")

【问题讨论】:

  • 而不是使用Kubernetes@1 使用azure cli 任务并运行az aks get-cred .. 然后运行您希望的命令并使用##vso[task.setvariable variable=SasToken;]$something" 抓取到输出

标签: azure azure-devops kubectl azure-aks


【解决方案1】:

我们可以使用日志记录命令##vso[task.setvariable variable=SasToken;]$something"set variables in scripts

但是根据您的描述,我们建议您使用output variable 来传递变量IP。例如,假设我们有一个名为MyTask 的任务,它设置了一个名为MyVar 的输出变量。我们可以在同一个作业中使用输出。

steps:
- task: MyTask@1  # this step generates the output variable
  name: ProduceVar  # because we're going to depend on it, we need to name the step
- script: echo $(ProduceVar.MyVar) # this step uses the output variable

【讨论】:

    【解决方案2】:

    我遵循了 Amit Baranes 建议的方法,因为我不清楚没有变量名的脚本执行分配。我已经使用了 Azure cli 任务并运行了它。成功了

              - task: AzureCLI@2
                  inputs:
                    azureSubscription: '<Service-Conn>'
                    scriptType: 'pscore'
                    scriptLocation: 'inlineScript'
                    inlineScript: |
                      az aks get-credentials -n $(clusterName) -g $(clusterRG)
                      $externalIp = (kubectl get -n $(ns) services $(svc) --output jsonpath='{.status.loadBalancer.ingress[0].ip}' )
                      Write-Host($externalIp) Write-Output("##vso[task.setvariable variable=AKSURL;]$externalIp")
    

    【讨论】:

    • 嗨,嗨,谢谢分享,你可以Accept it as an Answer,它可以帮助遇到同样问题的其他社区成员,我们可以存档这个帖子,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 2021-12-30
    • 2019-06-29
    • 2020-06-27
    • 1970-01-01
    • 2021-07-29
    • 2022-11-23
    相关资源
    最近更新 更多