I am trying to push an image to AKS using the default Azure DevOps template:
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- upload: manifests
artifact: manifests
Which results in the following error:
##[error]Path does not exist: /home/vsts/work/1/s/manifests
I've tried using the default Publish task
- task: PublishPipelineArtifact@1
inputs:
artifactName: 'manifests'
path: 'manifests'
but this did not change anything. Can somebody please explain, what is happening here and why the default template from Msft is not working?
Ok - at this stage I have to admin, that I had a thorough misunderstanding about artifacts in build pipelines.
The upload
(deprecated) and publish
tasks are short-hand for the Publish Pipeline Artifact task (https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml)
Second of all, the path behind the publish
keyword is the relative folder, that will be published. If you use the Kubernetes service template from Azure DevOps, it will create a manifest
folder on the root of your repo and pre-fill it with a deployment and service yml file.
I don't want them there (and must have deleted the folder subconciously), so I moved them and amended the path:
- publish: $(System.DefaultWorkingDirectory)/Code/Database/Docker
artifact: sql-drop
(The Docker folder is where I keep Dockerfiles, docker-compose, overrides and all te other jazz for spinning up containers)
Now in my deployment task, I need to be aware, that I cannot use the literal path from the repository. I need to download the artifact first, and then use the name of the artifact - "sql-drop" as the foldername:
steps:
#current means the current pipline. shorthand sytnax
- download: current
# name from the aritfact specifed above
artifact: sql-drop
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
# Use sql-drop as folder name and specify manifests
manifests: |
$(Pipeline.Workspace)/sql-drop/his-sql.dev.deployment.yml
$(Pipeline.Workspace)/sql-drop/his-sql.dev.service.yml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)