Reputation: 3064
I have an Azure Pipeline that builds a Docker container and uploads it to Azure Container Registry.
The source code chart is packaged, deployed on the temp artifact path, and then deployed to Kubernetes with Helm 3 commands.
- task: HelmDeploy@0
inputs:
command: 'package'
chartPath: Server/charts/server
destination: $(Build.ArtifactStagingDirectory)
- task: HelmDeploy@0
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceConnection: 'Staging12602128'
namespace: 'staging'
command: 'upgrade'
chartType: 'FilePath'
chartPath: '$(Build.ArtifactStagingDirectory)/server-0.0.1.tgz' <<== How to select latest version?
releaseName: 'server'
The destination on the package command, uses the latest version of the chart, and it's like this /home/vsts/work/1/a/server-0.1.1.tgz
The chartPath of the upgrade command, in all the examples, needs the exact version of the tgz package. How do I automatically insert the latest chart version in the "chartPath" in the upgrade task so I don't have to change it manually on every upgrade?
I tried without success:
chartPath: '$(Build.ArtifactStagingDirectory)/server-*.tgz'
chartPath: '$(Build.ArtifactStagingDirectory)/*.tgz'
chartPath: '$(Build.ArtifactStagingDirectory)/$(Build.SourceVersion).tgz'
chartPath: '$(Build.ArtifactStagingDirectory)/server-$(Build.DefinitionName).tgz'
Upvotes: 0
Views: 1867
Reputation: 40543
I'm not sure where your version number comes from, but even without that you can try thich approach:
- task: HelmDeploy@0
inputs:
command: 'package'
chartPath: Server/charts/server
destination: $(Build.ArtifactStagingDirectory)
- pwsh: |
$charts = Get-ChildItem
$sorted = $charts | sort -Descending
$latest = $sorted[0]
Write-Host "##vso[task.setvariable variable=chartName;]$latest"
workingDirectory: '$(Build.ArtifactStagingDirectory)'
- task: HelmDeploy@0
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceConnection: 'Staging12602128'
namespace: 'staging'
command: 'upgrade'
chartType: 'FilePath'
chartPath: '$(Build.ArtifactStagingDirectory)/$(chartName)' <<== How to select latest version?
releaseName: 'server'
Upvotes: 1