From 0d63da97183874af28a726d57041d3b81b7e99e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Ku=C5=9B?= Date: Thu, 4 Sep 2025 22:19:10 +0200 Subject: [PATCH] file-exist --- deploy-this/update-from-git.jenkinsfile | 52 +++++++++++-------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/deploy-this/update-from-git.jenkinsfile b/deploy-this/update-from-git.jenkinsfile index 6fd4781..fac0a61 100755 --- a/deploy-this/update-from-git.jenkinsfile +++ b/deploy-this/update-from-git.jenkinsfile @@ -7,43 +7,40 @@ def projects = [ "arti-angular-app" ] -def programs = "/_sd_/_programs_/" +def programs = "/_sd_/_programs_" def git_take(projects, git_remote) { withCredentials([usernamePassword(credentialsId: '9e8daaa4-8c14-41ae-947b-65ba47965dfe', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { - projects.each { project -> - def projectPath = "${programs}/${project}" - - if (fileExists(projectPath)) { - dir(projectPath) { + dir(programs) { + projects.each { project -> + if (fileExists(project)) { + dir(project) { + sh """ + echo "=== Updating ${project} ===" + git config --global --add safe.directory \$(pwd) + git remote set-url origin https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git + git fetch --depth=1000 origin main + git reset --hard origin/main + """ + } + } else { sh """ - echo "=== Updating ${project} ===" - git remote set-url origin https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git - git fetch --depth=1000 origin main - git reset --hard origin/main + echo "=== Cloning ${project} (last year only) ===" + git clone --shallow-since="1 year ago" https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git ${project} """ + dir(project) { + sh "git config --global --add safe.directory \$(pwd)" + } } - } else { - sh """ - echo "=== Cloning ${project} (last year only) ===" - git clone --shallow-since="1 year ago" https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git ${projectPath} - """ - if (!fileExists(projectPath)) { - error("❌ Nie udało się sklonować repozytorium ${project}") - } - } - dir(projectPath) { - sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short" + dir(project) { + sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short" + } } } } } -def disableSafeDirCheck() { - sh "git config --global --add safe.directory '*'" -} - pipeline { agent any @@ -51,10 +48,7 @@ pipeline { stage('Update from git') { steps { script { - disableSafeDirCheck() - dir("${programs}") { - git_take(projects, git_remote) - } + git_take(projects, git_remote) } } }