TL;DR: How do I mirror one repository to another using Jenkins multibranch pipeline?
I have a multibranch pipeline within Jenkins which I use to pull code from one repository, behind a firewall, to Azure Repos, on the open internet.
As of right now, I have only pushed the master branch as I did not see any need for other branches in Azure Repos. However, now one of my colleagues would like the other branches to be included. My current pipeline starts by creating a new git remote, pointing towards Azure Repos, which it, later on, uses together with a git push.
Example on the current pipeline:
pipeline {
agent any
stages {
stage('Setup') {
steps {
sh 'git remote add azure https://{{token}}@{{AzureRepoUrl}}'
}
}
stage('Push master') {
when {
branch 'master'
beforeAgent true
}
steps {
sh 'git push azure HEAD:refs/heads/${BRANCH_NAME}'
}
}
}
}
I can already see now that this will not work when including all branches, as there will be no clean-up of the branches when deleted in the origin remote.
I looked into using push --mirror but was unsuccessful as it ended up using Jenkins local repo since the multibranch pipeline checkout does not use --mirror.
Any suggestions on how I can mirror my origin remote into my azure remote?