restore update
This commit is contained in:
parent
0d63da9718
commit
2938e6143d
|
|
@ -10,31 +10,64 @@ 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')]) {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: '9e8daaa4-8c14-41ae-947b-65ba47965dfe',
|
||||
usernameVariable: 'GIT_USER',
|
||||
passwordVariable: 'GIT_PASS'
|
||||
)]) {
|
||||
// Upewnij się, że katalog bazowy istnieje
|
||||
sh "mkdir -p ${programs}"
|
||||
|
||||
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 https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git
|
||||
git fetch --depth=1000 origin main
|
||||
git reset --hard origin/main
|
||||
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 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
|
||||
"""
|
||||
}
|
||||
} 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)"
|
||||
sh """
|
||||
git config --global --add safe.directory \$(pwd)
|
||||
git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short || echo "Repo empty"
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
// 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"
|
||||
sh "git --no-pager log -n 1 --pretty=format:'%h %ad %s' --date=short || true"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -43,7 +76,6 @@ def git_take(projects, git_remote) {
|
|||
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
stages {
|
||||
stage('Update from git') {
|
||||
steps {
|
||||
|
|
|
|||
Loading…
Reference in New Issue