file-exist

This commit is contained in:
Artur Kuś 2025-09-04 22:19:10 +02:00
parent ede5718102
commit 0d63da9718
1 changed files with 23 additions and 29 deletions

View File

@ -7,17 +7,17 @@ def projects = [
"arti-angular-app" "arti-angular-app"
] ]
def programs = "/_sd_/_programs_/" def programs = "/_sd_/_programs_"
def git_take(projects, git_remote) { def git_take(projects, git_remote) {
withCredentials([usernamePassword(credentialsId: '9e8daaa4-8c14-41ae-947b-65ba47965dfe', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { withCredentials([usernamePassword(credentialsId: '9e8daaa4-8c14-41ae-947b-65ba47965dfe', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
dir(programs) {
projects.each { project -> projects.each { project ->
def projectPath = "${programs}/${project}" if (fileExists(project)) {
dir(project) {
if (fileExists(projectPath)) {
dir(projectPath) {
sh """ sh """
echo "=== Updating ${project} ===" 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 remote set-url origin https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git
git fetch --depth=1000 origin main git fetch --depth=1000 origin main
git reset --hard origin/main git reset --hard origin/main
@ -26,22 +26,19 @@ def git_take(projects, git_remote) {
} else { } else {
sh """ sh """
echo "=== Cloning ${project} (last year only) ===" 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} git clone --shallow-since="1 year ago" https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git ${project}
""" """
if (!fileExists(projectPath)) { dir(project) {
error("❌ Nie udało się sklonować repozytorium ${project}") sh "git config --global --add safe.directory \$(pwd)"
} }
} }
dir(projectPath) { dir(project) {
sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short" sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short"
} }
} }
} }
} }
def disableSafeDirCheck() {
sh "git config --global --add safe.directory '*'"
} }
pipeline { pipeline {
@ -51,12 +48,9 @@ pipeline {
stage('Update from git') { stage('Update from git') {
steps { steps {
script { script {
disableSafeDirCheck()
dir("${programs}") {
git_take(projects, git_remote) git_take(projects, git_remote)
} }
} }
} }
} }
} }
}