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,43 +7,40 @@ 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')]) {
projects.each { project -> dir(programs) {
def projectPath = "${programs}/${project}" projects.each { project ->
if (fileExists(project)) {
if (fileExists(projectPath)) { dir(project) {
dir(projectPath) { 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 """ sh """
echo "=== Updating ${project} ===" echo "=== Cloning ${project} (last year only) ==="
git remote set-url origin https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git git clone --shallow-since="1 year ago" https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git ${project}
git fetch --depth=1000 origin main
git reset --hard origin/main
""" """
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) { 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 {
agent any agent any
@ -51,10 +48,7 @@ pipeline {
stage('Update from git') { stage('Update from git') {
steps { steps {
script { script {
disableSafeDirCheck() git_take(projects, git_remote)
dir("${programs}") {
git_take(projects, git_remote)
}
} }
} }
} }