I am working on Azure DevOps with Azure Kubernetes Services.
I have a task to build custom Docker Image build number for each environment like Dev, Sit, Pre-prod, Prod separately likewise, Dev-0.0.1, Sit-0.0.1, Preprod-0.0.1, Prod-0.0.1 . Please suggest me with your solution.
My Pipeline looks like--
trigger:
- main
- dev
- pre-prod
- sit
pr: none
pool:
name: "mypool"
variables:
${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
namespace: prod
${{ elseif eq(variables['Build.SourceBranchName'], 'pre-prod') }}:
namespace: preprod
${{ elseif eq(variables['Build.SourceBranchName'], 'sit') }}:
namespace: sit
${{ elseif eq(variables['Build.SourceBranchName'], 'dev') }}:
namespace: dev
major-minor: '$(namespace).0.0'
revision: $[ counter(variables['major-minor'],0) ]
stages:
- stage: "build"
jobs:
- job: build
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean install'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: Docker@2
displayName: "Build image and publish to acr"
inputs:
containerRegistry: 'XXXXXXXXXXXX'
repository: 'XXXXXXXXXXXXX'
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
tags: '$(major-minor).$(revision)'