在HelmDeploy的任务之间共享管道变量

时间:2020-06-08 13:32:47

标签: azure azure-devops

我正在尝试通过Azure Devops运行Helm部署。问题是在实际的“升级”步骤中没有读取我在Bash步骤中设置的变量。当我从CLI单独运行此命令时,效果很好。

所以实际上是关于这一行的: arguments: "--reuse-values --version $(helmChartVersion)"

下面的全部内容:

- task: Bash@3
  name: repoAdd
  displayName: Add repo and deploy
  inputs:
    targetType: 'inline'
    script: |
      # Add the repo
      helm repo add \
        stapp \
        https://$(containerRegistry)/helm/v1/repo \
        --username $(registryUsername) \
        --password '$(registryPassword)'

      # Extra version file
      export helmChartVersion=$(jq .helmChartVersion $(pipeline.workspace)/ci-pipeline/build-artifact/variables.json -r)
      cat $(pipeline.workspace)/ci-pipeline/build-artifact/variables.json

      # Lets update the repo
      helm repo update

- task: HelmDeploy@0
  inputs:
    connectionType: 'Azure Resource Manager'
    azureSubscription: 'Microsoft Azure(1fafaf-8012-4035-b8f3-fafaffa)'
    azureResourceGroup: 'production-rg'
    kubernetesCluster: 'production'
    namespace: 'stapp-test'
    command: 'upgrade'
    chartType: 'Name'
    chartName: 'stapp/stapp'
    releaseName: 'stapp'
    install: false
    arguments: "--reuse-values --version $(helmChartVersion)"

最好, Pim

1 个答案:

答案 0 :(得分:1)

在Azure DevOps中,您必须使用Visual Studio Online中的旧标签显式设置变量。

# Extra version file
helmChartVersion=$(jq .helmChartVersion $(pipeline.workspace)/ci-pipeline/build-artifact/variables.json -r)
echo "##vso[task.setvariable variable=helmChartVersion]$helmChartVersion"

亚历山德罗·塞加拉(Alessandro Segala)为此撰写了一篇很棒的文章(https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763