问题
I am designing a Jenkins CICD pipeline at my organization and I have a following question.
I am from a devops team that controls the Jenkins pipeline for multiple development teams. I basically want to write a Jenkins file with multiple stages that can be run by multiple teams. I understand that this Jenkins file can be checked into the Gitrepo of each team and it can invoke the complete pipeline as soon as the changes are done to the code repo.
To make sure that this JenkinsFile is maintainable and for any future changes to this Jenkins file I dont have to ask all the various teams to update this file in their Gitrepo , I want to place this file at a central Gitrepo that is controlled by my team.
Is it possible to invoke this Jenkins file from different Gitrepos? Any examples?
回答1:
Here is how I could do it:
My Base repo simply called a remote repo like this :
#!/usr/bin/env groovy
def jenkinsFile
stage('Loading Jenkins file') {
jenkinsFile = fileLoader.fromGit('testjenkinsstuff/cicd/testMyPipeline', 'https://github.myorg.com/user/testjenkinsstuff.git', 'master', null, '')
}
jenkinsFile.start()
回答2:
To answer you question yes it is possible. To achive it approach has to be changed (i.e) there are no straight forward configuration available up to my understanding.
- Configure a pipeline job with "Pipeline from SCM" configured to DevOps maintained repo.
- Do not enable "Build when a changes pushed to SCM" as we configured github repo is different from user/project github repo
- Create a small webhook script and configure it in "GitHub Webhooks", hence it make a calls to respective jenkins job when there is a push (or) any other cond.
- Your pipeline script should be capable enough to design the "SCM url". For ex: checkout scm:http://github.org.net/${JOB_NAME}.git, here url is built using jenkins job name.
- If any project related details has to be maintained seperately (i.e) maven/ant/gradle compilation (or) any other information, make use of Shared Library resources to maintain hard coded inputs per project.
来源:https://stackoverflow.com/questions/44766324/invoke-a-remote-jenkins-file-from-another-jenkinsfile