Implemented auto commit new app version to GitOps by pipeline
This commit is contained in:
32
.jenkins/Jenkinsfile
vendored
32
.jenkins/Jenkinsfile
vendored
@ -37,13 +37,37 @@ pipeline {
|
||||
steps {
|
||||
container('docker') {
|
||||
sh '''
|
||||
docker build -t ${DOCKER_IMAGE} .
|
||||
az login --identity --client-id ${CLIENT_ID}
|
||||
az acr login --name ${ACR_NAME}
|
||||
docker push ${DOCKER_IMAGE}
|
||||
docker build -t ${DOCKER_IMAGE} .
|
||||
az login --identity --client-id ${CLIENT_ID}
|
||||
az acr login --name ${ACR_NAME}
|
||||
docker push ${DOCKER_IMAGE}
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Commit new version to GitOps repo') {
|
||||
steps {
|
||||
container('git') {
|
||||
sh '''
|
||||
git config --global user.name "jenkins[bot]"
|
||||
git config --global user.email "jenkins@marcin00.pl"
|
||||
'''
|
||||
sh '''
|
||||
# Podmień tag obrazu w pliku deploy.yaml
|
||||
awk -v commit="$GIT_COMMIT" '
|
||||
$0 ~ /name:[[:space:]]*api/ { in_api_container = 1; print; next }
|
||||
in_api_container && $0 ~ /^[[:space:]]*image:[[:space:]]*/ {
|
||||
sub(/:[^:[:space:]]+$/, ":" commit)
|
||||
in_api_container = 0
|
||||
print
|
||||
next
|
||||
}
|
||||
{ print }
|
||||
' deploy.yaml > deploy.tmp && mv deploy.tmp deploy.yaml
|
||||
'''
|
||||
sh 'git commit -am "JENKINS: Changed deployed version to $GIT_COMMIT"'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user