I saw few links where I can tag my docker image using ${Build.SourceVersion} in azure devops pipeline.
But it is using the complete ID of the commit.
But I want to use only the short ID.
I mean this (2cc7968) instead of this (2cc79689fc29ad69698d3062688e2a650da62b8e)
How to get this?
My pipeline:
# Deploy to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: "685f0716-8b46-436e-8d2a-3d0ff987fce9"
imageRepository: "azuredevopssampleapp"
containerRegistry: "aksdevopsacrtesting.azurecr.io"
dockerfilePath: "**/Dockerfile"
tag: "$(Build.BuildId)"
imagePullSecret: "aksdevopsacrtesting458647f2-auth"
# Agent VM image name
vmImageName: "ubuntu-latest"
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: pipeline_content/manifests
artifact: manifests
Not sure if it is the best way, but I've done it through user variables: