Invoke a remote jenkins file from another Jenkinsfile

故事扮演 提交于 2019-12-04 13:57:55

问题


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.

  1. Configure a pipeline job with "Pipeline from SCM" configured to DevOps maintained repo.
  2. Do not enable "Build when a changes pushed to SCM" as we configured github repo is different from user/project github repo
  3. 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.
  4. 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.
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!