Added saving known_hosts to file

This commit is contained in:
Marcin-Ramotowski
2025-07-08 19:03:23 +02:00
parent 1de32691c6
commit 49f19dabe6

29
.jenkins/Jenkinsfile vendored
View File

@ -10,7 +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' DEPLOY_REPO = 'ssh://git@srv22.mikr.us:20343/pikram/user-microservice-deploy.git'
} }
stages { stages {
@ -49,15 +49,23 @@ pipeline {
stage('Commit new version to GitOps repo') { stage('Commit new version to GitOps repo') {
steps { steps {
container('git') { container('git') {
sh ''' withCredentials([string(credentialsId: 'gitea-known-host', variable: 'GITEA_KNOWN_HOST')]) {
git config --global user.name "jenkins[bot]" sh '''
git config --global user.email "jenkins@marcin00.pl" mkdir -p ~/.ssh
''' echo "$GITEA_KNOWN_HOST" >> ~/.ssh/known_hosts
sh 'git clone ${DEPLOY_REPO} --branch jenkins-kubernetes' chmod 644 ~/.ssh/known_hosts
git config --global user.name "jenkins[bot]"
git config --global user.email "jenkins@marcin00.pl"
git clone ${DEPLOY_REPO} --branch jenkins-kubernetes
'''
}
dir('user-microservice-deploy') { dir('user-microservice-deploy') {
sh ''' sh '''
# Podmień tag obrazu w pliku deploy.yaml # Podmień tag obrazu w pliku deploy.yaml
awk -v commit="ssh-creds-id$GIT_COMMIT" ' awk -v commit="$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)
@ -68,11 +76,12 @@ pipeline {
{ print } { print }
' 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"'
sshagent(['gitea-deploy-key']) { sshagent(['gitea-deploy-key']) {
sh ''' sh '''
git remote set-url origin ssh://git@srv22.mikr.us:20343/pikram/user-microservice-deploy.git git add deploy.yaml
git push git diff-index --quiet HEAD || git commit -m "JENKINS: Changed deployed version to $GIT_COMMIT"
git push origin jenkins-kubernetes
''' '''
} }
} }