diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index aa156a7..c6c347b 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -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"' + } + } + } } } diff --git a/.jenkins/podTemplate.yaml b/.jenkins/podTemplate.yaml index cb854c6..ce523d4 100644 --- a/.jenkins/podTemplate.yaml +++ b/.jenkins/podTemplate.yaml @@ -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