Added git clone and git push with credentials

This commit is contained in:
Marcin-Ramotowski
2025-07-04 23:33:28 +02:00
parent e91273888a
commit 023daf1d4b

View File

@ -10,6 +10,7 @@ pipeline {
CLIENT_ID = 'c302726f-fafb-4143-94c1-67a70975574a' CLIENT_ID = 'c302726f-fafb-4143-94c1-67a70975574a'
DOCKER_REGISTRY_URL = 'marcin00.azurecr.io' DOCKER_REGISTRY_URL = 'marcin00.azurecr.io'
DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}" DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}"
DEPLOY_REPO = 'https://gitea.marcin00.pl/pikram/user-microservice-deploy.git'
} }
stages { stages {
@ -52,9 +53,11 @@ pipeline {
git config --global user.name "jenkins[bot]" git config --global user.name "jenkins[bot]"
git config --global user.email "jenkins@marcin00.pl" git config --global user.email "jenkins@marcin00.pl"
''' '''
sh 'git clone ${DEPLOY_REPO} --branch jenkins-kubernetes'
dir('user-microservice-deploy') {
sh ''' sh '''
# Podmień tag obrazu w pliku deploy.yaml # Podmień tag obrazu w pliku deploy.yaml
awk -v commit="$GIT_COMMIT" ' awk -v commit="ssh-creds-id$GIT_COMMIT" '
$0 ~ /name:[[:space:]]*api/ { in_api_container = 1; print; next } $0 ~ /name:[[:space:]]*api/ { in_api_container = 1; print; next }
in_api_container && $0 ~ /^[[:space:]]*image:[[:space:]]*/ { in_api_container && $0 ~ /^[[:space:]]*image:[[:space:]]*/ {
sub(/:[^:[:space:]]+$/, ":" commit) sub(/:[^:[:space:]]+$/, ":" commit)
@ -66,6 +69,10 @@ pipeline {
' deploy.yaml > deploy.tmp && mv deploy.tmp deploy.yaml ' deploy.yaml > deploy.tmp && mv deploy.tmp deploy.yaml
''' '''
sh 'git commit -am "JENKINS: Changed deployed version to $GIT_COMMIT"' sh 'git commit -am "JENKINS: Changed deployed version to $GIT_COMMIT"'
sshagent(['gitea-deploy-key']) {
sh 'git push'
}
}
} }
} }
} }