Implemented auto commit new app version to GitOps by pipeline

This commit is contained in:
Marcin-Ramotowski
2025-07-04 22:42:51 +02:00
parent 600b5aeba8
commit 247798abc8
2 changed files with 36 additions and 4 deletions

32
.jenkins/Jenkinsfile vendored
View File

@ -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"'
}
}
}
}
}

View File

@ -40,6 +40,14 @@ spec:
- name: workspace-volume
mountPath: /home/jenkins/agent
- name: git
image: alpine/git:latest
tty: true
workingDir: /home/jenkins/agent
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
nodeSelector:
kubernetes.io/os: linux