Dirkos
Dirkos

Reputation: 676

Share pipeline variable between tasks for HelmDeploy

Im trying to run an Helm deployment via Azure Devops. The problem is that the variable i set in my Bash step is not being read in the actual Upgrade step. When i run this command stand alone from my CLI it works fine.

So it is actually about this line: arguments: "--reuse-values --version $(helmChartVersion)"

The full thing below:

- 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)"

Best, Pim

Upvotes: 1

Views: 597

Answers (1)

Alduthir
Alduthir

Reputation: 36

In Azure DevOps you must explicitly set the variable with a legacy label from 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 has written a great article about this (https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763)

Upvotes: 1

Related Questions