feat: Add Jenkins pipeline for mirroring repositories from Gitea to GitHub

This commit is contained in:
Thibault Pouch
2026-03-23 11:36:20 +01:00
parent 3d255bdea2
commit de535943f9

77
Nest/mirror-repo.groovy Normal file
View File

@@ -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"
}
}
}