use the same Jenkinsfile for several github repositories
To accomplish this, I would suggest to create a pipeline with two parameters and pass the values based on the repo to build. 1) GIT BRANCH - to build and deploy required branch
2) GIT URL - to provide the git URL to checkout the code.
Providing a reference template.
node('NODE NAME') { withEnv([REQUIRED ENV VARIBALES]) { withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'CREDENTIALS ID', passwordVariable: 'PW', usernameVariable: 'USER']]) { try { stage 'Build' checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: gitbranch]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'CREDENTIALS ID', url: 'GIT URL']]] **** MAVEN BUILD **** stage 'Docker Image build & Push' ***** DOCKER BUILD AND PUSH TO REPO ***** } catch (err) { notify("Failed ${err}") currentBuild.result = 'FAILURE' } stage 'Deploy to ENV' ***** DEPLOYMENT TO REQUIRED ENV ***** notify('Success -Deployed to Environment') catch (err) { notify("Failed ${err}") currentBuild.result = 'FAILURE' } } }}def notify(status){****NOTIFICATION FUCNTION****}
Link the Jenkinsfile in the pipeline job and provide the values- build with parameters, while building the Jenkins job.
Hope this helps.