def git_remote = "https://git.arti24.eu/gitea" def projects = [ "proxy-nginx", "arti24", "angular-services", "arti-angular-app" ] 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) { 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 """ } } 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" } } } } def disableSafeDirCheck() { sh "git config --global --add safe.directory '*'" } pipeline { agent any stages { stage('Update from git') { steps { script { disableSafeDirCheck() dir("${programs}") { git_take(projects, git_remote) } } } } } }