Azure devops pipeline script -I
azure-pipelines.yml
variables:
- group: cr-variables
- ${{ if eq(variables['Build.SourceBranchName'], 'cibc-dev') }}:
- group: cr-variables-cibc-dev
- ${{ elseif eq(variables['Build.SourceBranchName'], 'cibc-dev2') }}:
- group: cr-variables-cibc-dev2
- ${{ elseif eq(variables['Build.SourceBranchName'], 'cibc-dev3') }}:
- group: cr-variables-cibc-dev3
- ${{ elseif eq(variables['Build.SourceBranchName'], 'cibc-sit') }}:
- group: cr-variables-cibc-sit
- ${{ elseif eq(variables['Build.SourceBranchName'], 'cibc-sit2') }}:
- group: cr-variables-cibc-sit2
- ${{ elseif eq(variables['Build.SourceBranchName'], 'cibc-sit3') }}:
- group: cr-variables-cibc-sit3
- name: container-tag
${{ if startsWith(variables['Build.SourceBranchName'], 'cibc-dev') }}:
value: $(container-version)
${{ elseif startsWith(variables['Build.SourceBranchName'], 'cibc-sit') }}:
value: $(Build.BuildNumber)
${{ else }}:
value: $(Build.SourceBranchName)
- name: container-relative-image-url
value: $(container-path)/$(Build.Repository.Name):$(container-tag)
pool:
name: dcore-build
steps:
- script: |
echo "***** env *****"
env
echo "***** pwd *****"
pwd
echo "***** ls -al *****"
ls -al
echo "***** java -version *****"
java -version
echo "***** mvn -version *****"
mvn -version
echo "***** docker version *****"
sudo docker version
echo "***** oc version *****"
oc version
echo "***** helm version *****"
helm version
displayName: 'Check LINUX Environment'
- script: |
#if [ type -P gradle >& /dev/null && gradle -version | grep -q "Gradle 7.0" ]; then
export GRADLE=gradle;
#else
# export GRADLE=./gradlew;
#fi
$GRADLE clean bootJar \
-PstarterVersion=$(starter-version) \
-PpublishMavenRepoUrl=$(publish-maven-repo-url) \
-PstarterVersionOMS=$(starter-version-oms) \
-PpublishMavenRepoUrlOMS=$(publish-maven-repo-url-oms) \
-PpublishMavenLoginId=$(publish-maven-repo-login-id) \
-PpublishMavenLoginPw=$(publish-maven-repo-login-pw) \
-PmavenRepoUrl=$(maven-repo-url) \
-PmavenLoginId=$(maven-repo-login-id) \
-PmavenLoginPw=$(maven-repo-login-pw)
condition: not(contains(variables['Build.SourceVersionMessage'], '#skip-ci'))
displayName: 'build gradle'
- script: sed -i "1 s#.*#FROM $(image-java8)#" Dockerfile
displayName: 'docker from'
- script: sudo docker build -t $(container-repo-url)/$(container-relative-image-url) .
condition: and(succeeded(), not(contains(variables['Build.SourceVersionMessage'], '#skip-ci')))
displayName: 'docker build'
- script: sudo docker login -u $(container-repo-login-id) -p $(container-repo-login-pw) $(container-repo-url)
displayName: 'docker login'
- script: sudo docker push $(container-repo-url)/$(container-relative-image-url)
condition: and(succeeded(), not(contains(variables['Build.SourceVersionMessage'], '#skip-ci')))
displayName: 'docker push'
- script: sudo docker logout $(container-repo-url)
condition: always()
displayName: 'docker logout'
- script: sudo docker tag $(container-repo-url)/$(container-relative-image-url) $(container-publish-repo-url)/$(container-relative-image-url)
condition: and(succeeded(), startsWith(variables['Build.SourceBranchName'], 'cibc-sit'), not(contains(variables['Build.SourceVersionMessage'], '#skip-ci')))
displayName: 'UAT docker image tag'
- script: sudo docker login -u $(container-publish-repo-login-id) -p $(container-publish-repo-login-pw) $(container-publish-repo-url)
displayName: 'UAT docker login'
- script: sudo docker push $(container-publish-repo-url)/$(container-relative-image-url)
condition: and(succeeded(), startsWith(variables['Build.SourceBranchName'], 'cibc-sit'), not(contains(variables['Build.SourceVersionMessage'], '#skip-ci')))
displayName: 'UAT docker push'
- script: sudo docker logout $(container-publish-repo-url)
condition: always()
displayName: 'UAT docker logout'
- script: |
sudo docker rmi -f $(sudo docker images --filter "dangling=true" -q --no-trunc)
exit 0
condition: always()
displayName: 'docker rmi (dependency cleanup)'
- script: sudo docker rmi $(container-publish-repo-url)/$(container-relative-image-url)
condition: and(always(), startsWith(variables['Build.SourceBranchName'], 'cibc-sit'), not(contains(variables['Build.SourceVersionMessage'], '#skip-ci')))
displayName: 'docker rmi (UAT image cleanup)'
- script: sudo docker rmi $(container-repo-url)/$(container-relative-image-url)
condition: and(always(), not(contains(variables['Build.SourceVersionMessage'], '#skip-ci')))
displayName: 'docker rmi (image cleanup)'
- script: |
sed -i -e 's#export CONTAINER_IMAGE=#export CONTAINER_IMAGE=$(container-repo-url)/$(container-relative-image-url)#g' azure-pipelines-deploy.sh
sed -i -e 's#export CONTAINER_IMAGE=#export CONTAINER_IMAGE=$(container-publish-repo-url)/$(container-relative-image-url)#g' helm/deploy.env
displayName: 'deployment artifact variables'
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.Repository.LocalPath)'
Contents: |
$(Build.Repository.LocalPath)/helm/**
$(Build.Repository.LocalPath)/azure-pipelines-deploy.sh
TargetFolder: '$(Build.ArtifactStagingDirectory)'
CleanTargetFolder: true
OverWrite: true
condition: succeeded()
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: '$(Build.DefinitionName)'
publishLocation: 'Container'
condition: succeeded()
- task: UniversalPackages@0
inputs:
command: 'publish'
publishDirectory: '$(Build.ArtifactStagingDirectory)'
feedsToUsePublish: 'external'
publishFeedCredentials: '$(universal-feed-service-connection)'
feedPublishExternal: '$(universal-feed-project)/$(universal-feed-name)'
packagePublishExternal: '$(Build.Repository.Name)'
versionOption: custom
versionPublish: '1.$(Build.BuildNumber)'
condition: and(succeeded(), startsWith(variables['Build.SourceBranchName'], 'cibc-sit'))
displayName: 'UAT universal feed publish'
No comments: