Update azure-pipelines.yml for Azure Pipelines

This commit is contained in:
shamrao shinde, sumedh
2024-11-08 07:15:21 +00:00
parent 147b44d931
commit ba515f9de9

View File

@@ -1,87 +1,95 @@
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
trigger: trigger:
- master - master
pool:
name: azureselfhosted
variables: variables:
dockerRegistryServiceConnection: 'docker-registry-olympus' dockerRegistryServiceConnection: 'docker-registry-olympus'
imageName: 'apollo' # Replace with your Docker image name imageName: 'apollo'
shortCommitSha: '' # Initialize variable for short commit SHA shortCommitSha: ''
resources: envName: 'aks-olympus'
repositories:
- repository: olympus-common # Alias for the first repository stages:
type: git - stage: Build
name: Olympus/olympus-common # Project and repository name displayName: Build stage
ref: master jobs:
steps: - job: Build
- checkout: self # Check out the pipeline repository (optional) displayName: Build
- checkout: olympus-common # Check out the first repository pool:
# Extract the short commit SHA name: azureselfhosted
- script: | steps:
echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-7)" - checkout: self
displayName: 'Set Short Commit SHA'
- script: | - script: |
echo "Building the first repository..." echo "##vso[task.setvariable variable=shortCommitSha]$(Build.SourceVersion.SHA.Substring(0, 8))"
ls -lrth displayName: 'Set Short Commit SHA'
displayName: 'List olympus-common'
- task: Maven@3 - script: |
inputs: echo "Building the first repository..."
mavenPomFile: 'olympus-common/pom.xml' ls -lrth
goals: 'install' displayName: 'List olympus-common'
# options: '-s $(mvnSettings.secureFilePath)'
#mavenAuthenticateFeed: true - task: Maven@3
#publishJUnitResults: true inputs:
#testResultsFiles: '**/TEST-*.xml' mavenPomFile: 'olympus-common/pom.xml'
#javaHomeOption: 'JDKVersion' goals: 'install'
#jdkVersionOption: '1.21' displayName: 'Build olympus-common'
#mavenVersionOption: 'Default'
displayName: 'Build olympus-common' - task: Maven@3
- task: Maven@3 inputs:
inputs: mavenPomFile: 'apollo/pom.xml'
mavenPomFile: 'apollo/pom.xml' goals: 'install -DskipTests'
goals: 'install -DskipTests' displayName: 'Build apollo'
# options: '-s $(mvnSettings.secureFilePath)'
#mavenAuthenticateFeed: true - script: |
#publishJUnitResults: true echo "Listing the docker images..."
#testResultsFiles: '**/TEST-*.xml' docker images
#javaHomeOption: 'JDKVersion' displayName: 'List docker images1'
#jdkVersionOption: '1.21'
#mavenVersionOption: 'Default' - task: Docker@2
displayName: 'Build apollo' inputs:
- script: | command: 'buildAndPush'
echo "Listing the docker images..." containerRegistry: $(dockerRegistryServiceConnection)
docker images repository: '$(imageName)'
displayName: 'List docker images1' tags: '$(shortCommitSha)'
- task: Docker@2 Dockerfile: 'apollo/Dockerfile'
inputs:
command: 'buildAndPush' - script: |
containerRegistry: $(dockerRegistryServiceConnection) echo "Listing the docker images..."
repository: '$(imageName)' docker images
tags: '$(shortCommitSha)' displayName: 'List docker images'
Dockerfile: 'apollo/Dockerfile'
- script: | - stage: Deploy
echo "Listing the docker images..." displayName: Deploy stage
docker images jobs:
displayName: 'List docker images' - deployment: Deploy
- script: | displayName: Deploy to $(envName)
echo "Updating imageName in dpeloyment.yaml" condition: succeeded()
echo "Before Substitution" pool:
cat apollo/apollo-deployment.yaml name: azureselfhosted
echo "###############################################" environment: $(envName)
echo "current shell: $SHELL" strategy:
echo "imagename bracket : $(imageName)" runOnce:
echo "###############################################" deploy:
sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" apollo/apollo-deployment.yaml steps:
echo "After Substitution" - script: |
cat apollo/apollo-deployment.yaml echo "Updating imageName in dpeloyment.yaml"
displayName: 'Update ImageName in YAML file' echo "Before Substitution"
- script: | cat apollo/apollo-deployment.yaml
echo "deployment using kubectl" echo "###############################################"
kubectl apply -f apollo/apollo-deployment.yaml echo "current shell: $SHELL"
displayName: 'deployment using kubectl' echo "imagename bracket : $(imageName)"
- script: | echo "###############################################"
echo "remove the docker images..." sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" apollo/apollo-deployment.yaml
docker rmi $(docker images -q) echo "After Substitution"
displayName: 'remove docker images' cat apollo/apollo-deployment.yaml
displayName: 'Update ImageName in YAML file'
- script: |
echo "deployment using kubectl"
kubectl apply -f apollo/apollo-deployment.yaml
displayName: 'Deployment using kubectl'
- script: |
echo "Removing Docker images to clean up..."
docker rmi $(docker images -q)
displayName: 'Clean up Docker Images'
continueOnError: true