From c145e2e8543b2a50285d05e181ab4e03efb365f9 Mon Sep 17 00:00:00 2001 From: 12ww1160 <12ww1160@confdroid.com> Date: Sat, 13 Jun 2026 14:40:50 +0200 Subject: [PATCH] OP#618 add ssh-agent to last stage --- Jenkinsfile | 62 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 360c774..77e7a89 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -108,36 +108,38 @@ pipeline { } stage('Mirror to Gitea') { steps { - withCredentials([usernamePassword( - credentialsId: 'Jenkins-gitea', - usernameVariable: 'GITEA_USER', - passwordVariable: 'GITEA_TOKEN')]) { - script { - sh ''' - git fetch --tags origin - git checkout -B gitea-mirror-$BUILD_NUMBER origin/master - git rm -f Jenkinsfile - git commit -m "Remove Jenkinsfile for Gitea mirror" || echo "No changes to commit" - git remote get-url master >/dev/null 2>&1 \ - && git remote set-url master https://sourcecode.confdroid.com/confdroid/confdroid_jenkins.git \ - || git remote add master https://sourcecode.confdroid.com/confdroid/confdroid_jenkins.git - git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ - push --force master HEAD:refs/heads/master - git ls-remote --heads master | awk '{print $2}' | sed 's#refs/heads/##' | while read branch; do - if [ -n "$branch" ] && [ "$branch" != "master" ]; then - git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ - push master --delete "$branch" - fi - done - git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ - push master --tags - git ls-remote --tags master | awk '{print $2}' | sed 's#refs/tags/##' | cut -d'^' -f1 | sort -u | while read tag; do - if [ -n "$tag" ] && ! git show-ref --tags --verify --quiet "refs/tags/$tag"; then - git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ - push master ":refs/tags/$tag" - fi - done - ''' + sshagent(['edd05eb6-26b5-4c7b-a5cc-ea2ab899f4fa']) { + withCredentials([usernamePassword( + credentialsId: 'Jenkins-gitea', + usernameVariable: 'GITEA_USER', + passwordVariable: 'GITEA_TOKEN')]) { + script { + sh ''' + git fetch --tags origin + git checkout -B gitea-mirror-$BUILD_NUMBER origin/master + git rm -f Jenkinsfile + git commit -m "Remove Jenkinsfile for Gitea mirror" || echo "No changes to commit" + git remote get-url master >/dev/null 2>&1 \ + && git remote set-url master https://sourcecode.confdroid.com/confdroid/confdroid_jenkins.git \ + || git remote add master https://sourcecode.confdroid.com/confdroid/confdroid_jenkins.git + git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ + push --force master HEAD:refs/heads/master + git ls-remote --heads master | awk '{print $2}' | sed 's#refs/heads/##' | while read branch; do + if [ -n "$branch" ] && [ "$branch" != "master" ]; then + git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ + push master --delete "$branch" + fi + done + git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ + push master --tags + git ls-remote --tags master | awk '{print $2}' | sed 's#refs/tags/##' | cut -d'^' -f1 | sort -u | while read tag; do + if [ -n "$tag" ] && ! git show-ref --tags --verify --quiet "refs/tags/$tag"; then + git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ + push master ":refs/tags/$tag" + fi + done + ''' + } } } }