From de535943f927e59d18de80d1e05da453a66a52bf Mon Sep 17 00:00:00 2001 From: Thibault Pouch Date: Mon, 23 Mar 2026 11:36:20 +0100 Subject: [PATCH] feat: Add Jenkins pipeline for mirroring repositories from Gitea to GitHub --- Nest/mirror-repo.groovy | 77 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Nest/mirror-repo.groovy diff --git a/Nest/mirror-repo.groovy b/Nest/mirror-repo.groovy new file mode 100644 index 0000000..579e78d --- /dev/null +++ b/Nest/mirror-repo.groovy @@ -0,0 +1,77 @@ +pipeline { + agent any + + parameters { + string( + name: 'SOURCE_REPO_URL', + defaultValue: 'https://git.crowmate.fr/crowmate/Nest.git', + description: 'Gitea repository URL to clone' + ) + string( + name: 'MIRROR_REPO_URL', + defaultValue: 'https://github.com/CrowMate/Nest.git', + description: 'GitHub repository URL to mirror to' + ) + string( + name: 'BRANCH', + defaultValue: 'main', + description: 'Branch to mirror' + ) + } + + environment { + GITHUB_CREDENTIALS_ID = 'github-token' + GITEA_CREDENTIALS_ID = 'gitea-token' + } + + stages { + + stage('Clone from Gitea') { + steps { + cleanWs() + checkout([ + $class: 'GitSCM', + branches: [[name: "*/${params.BRANCH}"]], + extensions: [[ + $class: 'CloneOption', + noTags: false, + shallow: false + ]], + userRemoteConfigs: [[ + url: params.SOURCE_REPO_URL, + credentialsId: env.GITEA_CREDENTIALS_ID + ]] + ]) + echo "Repository cloned from Gitea" + } + } + + stage('Push to GitHub') { + steps { + withCredentials([usernamePassword( + credentialsId: env.GITHUB_CREDENTIALS_ID, + usernameVariable: 'MIRROR_USER', + passwordVariable: 'MIRROR_PASS' + )]) { + sh ''' + MIRROR_URL_AUTH=$(echo "''' + params.MIRROR_REPO_URL + '''" | sed "s|https://|https://$MIRROR_USER:$MIRROR_PASS@|") + git remote add mirror "$MIRROR_URL_AUTH" + git push mirror '+refs/heads/*:refs/heads/*' --force + git push mirror '+refs/tags/*:refs/tags/*' --force + echo "Repository mirrored to GitHub successfully" + ''' + } + } + } + + } + + post { + success { + echo "Mirror of '${params.SOURCE_REPO_URL}' to '${params.MIRROR_REPO_URL}' completed successfully" + } + failure { + echo "Mirror failed" + } + } +}