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 {
|
steps {
|
||||||
container('docker') {
|
container('docker') {
|
||||||
sh '''
|
sh '''
|
||||||
docker build -t ${DOCKER_IMAGE} .
|
docker build -t ${DOCKER_IMAGE} .
|
||||||
az login --identity --client-id ${CLIENT_ID}
|
az login --identity --client-id ${CLIENT_ID}
|
||||||
az acr login --name ${ACR_NAME}
|
az acr login --name ${ACR_NAME}
|
||||||
docker push ${DOCKER_IMAGE}
|
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"'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,14 @@ spec:
|
|||||||
- name: workspace-volume
|
- name: workspace-volume
|
||||||
mountPath: /home/jenkins/agent
|
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:
|
nodeSelector:
|
||||||
kubernetes.io/os: linux
|
kubernetes.io/os: linux
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user