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"
]
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)
}
}
}