From 19a05f82eb3756b97142fbb9e0fd2aff4fdca89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Ku=C5=9B?= Date: Thu, 4 Sep 2025 22:56:50 +0200 Subject: [PATCH] workspace jenkinsa to _sd_ --- deploy-this/update-from-git.jenkinsfile | 51 ++++++------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/deploy-this/update-from-git.jenkinsfile b/deploy-this/update-from-git.jenkinsfile index 37a06ea..2a6398b 100755 --- a/deploy-this/update-from-git.jenkinsfile +++ b/deploy-this/update-from-git.jenkinsfile @@ -10,64 +10,31 @@ def projects = [ def programs = "/_sd_/_programs_" def git_take(projects, git_remote) { - withCredentials([usernamePassword( - credentialsId: '9e8daaa4-8c14-41ae-947b-65ba47965dfe', - usernameVariable: 'GIT_USER', - passwordVariable: 'GIT_PASS' - )]) { - // Upewnij się, że katalog bazowy istnieje - sh "mkdir -p ${programs}" - + withCredentials([usernamePassword(credentialsId: '9e8daaa4-8c14-41ae-947b-65ba47965dfe', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { dir(programs) { projects.each { project -> if (fileExists(project)) { dir(project) { sh """ - set -e echo "=== Updating ${project} ===" git config --global --add safe.directory \$(pwd) - git remote set-url origin ${git_remote}/${project}.git - # Wstrzykuj poświadczenia tylko dla tego fetch/resetu - git config http.${git_remote}/${project}.git.extraHeader "Authorization: Basic \$(printf '%s:%s' '${GIT_USER}' '${GIT_PASS}' | base64)" - - # Wykryj domyślny branch z origin/HEAD; fallback: main -> master - DEFAULT_BRANCH=\$(git remote show origin 2>/dev/null | sed -n '/HEAD branch/s/.*: //p') - [ -z "\$DEFAULT_BRANCH" ] && DEFAULT_BRANCH=main + git remote set-url origin https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git git fetch --prune origin - - # Spróbuj ustawić się na domyślny; jeśli nie istnieje, spróbuj main/master - if git rev-parse --verify origin/\$DEFAULT_BRANCH >/dev/null 2>&1; then - git checkout -B \$DEFAULT_BRANCH origin/\$DEFAULT_BRANCH - elif git rev-parse --verify origin/main >/dev/null 2>&1; then - git checkout -B main origin/main - elif git rev-parse --verify origin/master >/dev/null 2>&1; then - git checkout -B master origin/master - else - echo "⚠️ Brak znanych gałęzi (main/master). Repo może być puste." - fi - - # Wyczyść nagłówek z tokenem, żeby nie zostawał globalnie - git config --unset-all http.${git_remote}/${project}.git.extraHeader || true + git checkout -B main origin/main """ } } else { sh """ - set -e echo "=== Cloning ${project} (last year only) ===" - # Użyj URL bezpośrednio z poświadczeniami do klona (Jenkins zamaskuje hasło w logach) 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) - git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short || echo "Repo empty" - """ + sh "git config --global --add safe.directory \$(pwd)" } } - // log ostatniego commita (jeśli repo nie jest puste) dir(project) { - sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short || true" + sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short" } } } @@ -75,7 +42,13 @@ def git_take(projects, git_remote) { } pipeline { - agent any + agent { + node { + // ustawiamy workspace na Twój katalog + customWorkspace '/_sd_/_programs_' + } + } + stages { stage('Update from git') { steps {