From 3fec7091ba6eec688b43a442ac7736d2eac97696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Ku=C5=9B?= Date: Thu, 4 Sep 2025 12:05:03 +0200 Subject: [PATCH] =?UTF-8?q?Bezpiecznie=20u=C5=BCywa=C5=82=20po=C5=9Bwiadcz?= =?UTF-8?q?e=C5=84=20(withCredentials)=20=E2=80=93=20has=C5=82o=20nie=20wy?= =?UTF-8?q?cieknie=20w=20logach.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Obsługiwał aktualizację istniejących katalogów i klonowanie nowych. Pobierał tylko ostatni rok historii (--shallow-since="1 year ago"). Nie zostawiał pustych katalogów, jeśli klon się nie powiedzie. --- deploy-this/update-from-git.jenkinsfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/deploy-this/update-from-git.jenkinsfile b/deploy-this/update-from-git.jenkinsfile index 1338134..0bf1d9f 100755 --- a/deploy-this/update-from-git.jenkinsfile +++ b/deploy-this/update-from-git.jenkinsfile @@ -10,25 +10,28 @@ def projects = [ def git_take(projects, git_remote) { withCredentials([usernamePassword(credentialsId: 'c3c1f5bf-8f6e-4686-b26c-3f419ef7973e', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { projects.each { project -> + def projectPath = "${env.WORKSPACE}/${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 origin + git fetch --depth=1000 origin main git reset --hard origin/main """ - } } else { sh """ - git clone https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git || exit 1 + echo "=== Cloning ${project} (last year only) ===" + git clone --shallow-since="1 year ago" https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git """ if (!fileExists(project)) { - error("Nie udało się pobrać lub utworzyć katalogu projektu ${project}") + error("❌ Nie udało się sklonować repozytorium ${project}") } - } + dir(project) { sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short" } @@ -36,7 +39,6 @@ def git_take(projects, git_remote) { } } - def disableSafeDirCheck() { sh "git config --global --add safe.directory '*'" }