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,59 +1,49 @@
# 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:
- job: Build
displayName: Build
pool:
name: azureselfhosted
steps: steps:
- checkout: self # Check out the pipeline repository (optional) - checkout: self
- checkout: olympus-common # Check out the first repository
# Extract the short commit SHA
- script: | - script: |
echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-7)" echo "##vso[task.setvariable variable=shortCommitSha]$(Build.SourceVersion.SHA.Substring(0, 8))"
displayName: 'Set Short Commit SHA' displayName: 'Set Short Commit SHA'
- script: | - script: |
echo "Building the first repository..." echo "Building the first repository..."
ls -lrth ls -lrth
displayName: 'List olympus-common' displayName: 'List olympus-common'
- task: Maven@3 - task: Maven@3
inputs: inputs:
mavenPomFile: 'olympus-common/pom.xml' mavenPomFile: 'olympus-common/pom.xml'
goals: 'install' goals: 'install'
# options: '-s $(mvnSettings.secureFilePath)'
#mavenAuthenticateFeed: true
#publishJUnitResults: true
#testResultsFiles: '**/TEST-*.xml'
#javaHomeOption: 'JDKVersion'
#jdkVersionOption: '1.21'
#mavenVersionOption: 'Default'
displayName: 'Build olympus-common' 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'
# options: '-s $(mvnSettings.secureFilePath)'
#mavenAuthenticateFeed: true
#publishJUnitResults: true
#testResultsFiles: '**/TEST-*.xml'
#javaHomeOption: 'JDKVersion'
#jdkVersionOption: '1.21'
#mavenVersionOption: 'Default'
displayName: 'Build apollo' displayName: 'Build apollo'
- script: | - script: |
echo "Listing the docker images..." echo "Listing the docker images..."
docker images docker images
displayName: 'List docker images1' displayName: 'List docker images1'
- task: Docker@2 - task: Docker@2
inputs: inputs:
command: 'buildAndPush' command: 'buildAndPush'
@@ -61,10 +51,25 @@ steps:
repository: '$(imageName)' repository: '$(imageName)'
tags: '$(shortCommitSha)' tags: '$(shortCommitSha)'
Dockerfile: 'apollo/Dockerfile' Dockerfile: 'apollo/Dockerfile'
- script: | - script: |
echo "Listing the docker images..." echo "Listing the docker images..."
docker images docker images
displayName: 'List docker images' displayName: 'List docker images'
- stage: Deploy
displayName: Deploy stage
jobs:
- deployment: Deploy
displayName: Deploy to $(envName)
condition: succeeded()
pool:
name: azureselfhosted
environment: $(envName)
strategy:
runOnce:
deploy:
steps:
- script: | - script: |
echo "Updating imageName in dpeloyment.yaml" echo "Updating imageName in dpeloyment.yaml"
echo "Before Substitution" echo "Before Substitution"
@@ -77,11 +82,14 @@ steps:
echo "After Substitution" echo "After Substitution"
cat apollo/apollo-deployment.yaml cat apollo/apollo-deployment.yaml
displayName: 'Update ImageName in YAML file' displayName: 'Update ImageName in YAML file'
- script: | - script: |
echo "deployment using kubectl" echo "deployment using kubectl"
kubectl apply -f apollo/apollo-deployment.yaml kubectl apply -f apollo/apollo-deployment.yaml
displayName: 'deployment using kubectl' displayName: 'Deployment using kubectl'
- script: | - script: |
echo "remove the docker images..." echo "Removing Docker images to clean up..."
docker rmi $(docker images -q) docker rmi $(docker images -q)
displayName: 'remove docker images' displayName: 'Clean up Docker Images'
continueOnError: true