restore update
This commit is contained in:
parent
0d63da9718
commit
2938e6143d
|
|
@ -10,31 +10,64 @@ def projects = [
|
||||||
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'
|
||||||
|
)]) {
|
||||||
|
// Upewnij się, że katalog bazowy istnieje
|
||||||
|
sh "mkdir -p ${programs}"
|
||||||
|
|
||||||
dir(programs) {
|
dir(programs) {
|
||||||
projects.each { project ->
|
projects.each { project ->
|
||||||
if (fileExists(project)) {
|
if (fileExists(project)) {
|
||||||
dir(project) {
|
dir(project) {
|
||||||
sh """
|
sh """
|
||||||
|
set -e
|
||||||
echo "=== Updating ${project} ==="
|
echo "=== Updating ${project} ==="
|
||||||
git config --global --add safe.directory \$(pwd)
|
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 ${git_remote}/${project}.git
|
||||||
git fetch --depth=1000 origin main
|
# Wstrzykuj poświadczenia tylko dla tego fetch/resetu
|
||||||
git reset --hard origin/main
|
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 {
|
} else {
|
||||||
sh """
|
sh """
|
||||||
|
set -e
|
||||||
echo "=== Cloning ${project} (last year only) ==="
|
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}
|
git clone --shallow-since="1 year ago" https://${GIT_USER}:${GIT_PASS}@git.arti24.eu/gitea/${project}.git ${project}
|
||||||
"""
|
"""
|
||||||
dir(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) {
|
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 {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Update from git') {
|
stage('Update from git') {
|
||||||
steps {
|
steps {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue