From ba515f9de9a3ae9d3608304c0629b2be2f042d0e Mon Sep 17 00:00:00 2001 From: "shamrao shinde, sumedh" Date: Fri, 8 Nov 2024 07:15:21 +0000 Subject: [PATCH] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 176 +++++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 84 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ce0c0de..92b625e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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: -- master -pool: - name: azureselfhosted + - master + variables: dockerRegistryServiceConnection: 'docker-registry-olympus' - imageName: 'apollo' # Replace with your Docker image name - shortCommitSha: '' # Initialize variable for short commit SHA -resources: - repositories: - - repository: olympus-common # Alias for the first repository - type: git - name: Olympus/olympus-common # Project and repository name - ref: master -steps: -- checkout: self # Check out the pipeline repository (optional) -- checkout: olympus-common # Check out the first repository -# Extract the short commit SHA -- script: | - echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-7)" - displayName: 'Set Short Commit SHA' -- script: | - echo "Building the first repository..." - ls -lrth - displayName: 'List olympus-common' -- task: Maven@3 - inputs: - mavenPomFile: 'olympus-common/pom.xml' - goals: 'install' - # options: '-s $(mvnSettings.secureFilePath)' - #mavenAuthenticateFeed: true - #publishJUnitResults: true - #testResultsFiles: '**/TEST-*.xml' - #javaHomeOption: 'JDKVersion' - #jdkVersionOption: '1.21' - #mavenVersionOption: 'Default' - displayName: 'Build olympus-common' -- task: Maven@3 - inputs: - mavenPomFile: 'apollo/pom.xml' - goals: 'install -DskipTests' - # options: '-s $(mvnSettings.secureFilePath)' - #mavenAuthenticateFeed: true - #publishJUnitResults: true - #testResultsFiles: '**/TEST-*.xml' - #javaHomeOption: 'JDKVersion' - #jdkVersionOption: '1.21' - #mavenVersionOption: 'Default' - displayName: 'Build apollo' -- script: | - echo "Listing the docker images..." - docker images - displayName: 'List docker images1' -- task: Docker@2 - inputs: - command: 'buildAndPush' - containerRegistry: $(dockerRegistryServiceConnection) - repository: '$(imageName)' - tags: '$(shortCommitSha)' - Dockerfile: 'apollo/Dockerfile' -- script: | - echo "Listing the docker images..." - docker images - displayName: 'List docker images' -- script: | - echo "Updating imageName in dpeloyment.yaml" - echo "Before Substitution" - cat apollo/apollo-deployment.yaml - echo "###############################################" - echo "current shell: $SHELL" - echo "imagename bracket : $(imageName)" - echo "###############################################" - sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" apollo/apollo-deployment.yaml - echo "After Substitution" - 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 "remove the docker images..." - docker rmi $(docker images -q) - displayName: 'remove docker images' \ No newline at end of file + imageName: 'apollo' + shortCommitSha: '' + envName: 'aks-olympus' + +stages: + - stage: Build + displayName: Build stage + jobs: + - job: Build + displayName: Build + pool: + name: azureselfhosted + steps: + - checkout: self + + - script: | + echo "##vso[task.setvariable variable=shortCommitSha]$(Build.SourceVersion.SHA.Substring(0, 8))" + displayName: 'Set Short Commit SHA' + + - script: | + echo "Building the first repository..." + ls -lrth + displayName: 'List olympus-common' + + - task: Maven@3 + inputs: + mavenPomFile: 'olympus-common/pom.xml' + goals: 'install' + displayName: 'Build olympus-common' + + - task: Maven@3 + inputs: + mavenPomFile: 'apollo/pom.xml' + goals: 'install -DskipTests' + displayName: 'Build apollo' + + - script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images1' + + - task: Docker@2 + inputs: + command: 'buildAndPush' + containerRegistry: $(dockerRegistryServiceConnection) + repository: '$(imageName)' + tags: '$(shortCommitSha)' + Dockerfile: 'apollo/Dockerfile' + + - script: | + echo "Listing the docker images..." + 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: | + echo "Updating imageName in dpeloyment.yaml" + echo "Before Substitution" + cat apollo/apollo-deployment.yaml + echo "###############################################" + echo "current shell: $SHELL" + echo "imagename bracket : $(imageName)" + echo "###############################################" + sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" apollo/apollo-deployment.yaml + echo "After Substitution" + 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