From 7b8e1404214561bfaa47ec7bb50e2f8856b77539 Mon Sep 17 00:00:00 2001 From: 12ww1160 <12ww1160@confdroid.com> Date: Sat, 13 Jun 2026 14:27:04 +0200 Subject: [PATCH] OP#618 add ssh-agent to last stage --- Jenkinsfile | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8647b2c..bceb0d9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -107,36 +107,25 @@ pipeline { } stage('Mirror to Gitea') { steps { + 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_java.git \ - || git remote add master https://sourcecode.confdroid.com/confdroid/confdroid_java.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 - ''' + credentialsId: 'Jenkins-gitea', + usernameVariable: 'GITEA_USER', + passwordVariable: 'GITEA_TOKEN')]) { + script { + // Checkout from GitLab (already done implicitly) + sh ''' + git checkout master + git pull origin master + git branch -D development + git branch -D jenkins-build-$BUILD_NUMBER + git rm -f Jenkinsfile + git rm -r --cached .vscode || echo "No .vscode to remove from git" + git commit --amend --no-edit --allow-empty + git remote add master https://sourcecode.confdroid.com/confdroid/confdroid_java.git + git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \ + push master --mirror + ''' } } }