How to share a Declarative Pipeline across many projects

前端 未结 3 1690
别跟我提以往
别跟我提以往 2021-02-10 09:57

I have a lot of projects in different repositories which share the same fundamental CI-workflow, which I can easily express as a Declarative Pipeline:

pipeline {         


        
3条回答
  •  走了就别回头了
    2021-02-10 10:11

    I have been dealing this same issue for my own work. The best solution I could come up with was include a generic Jenkinsfile in every project/repo in my organization:

    node
    {
      checkout([$class: 'GitSCM', branches: [[name: env.DELIVERY_PIPELINE_BRANCH]], userRemoteConfigs: [[credentialsId: env.DELIVERY_PIPELINE_CREDENTIALS, url: env.DELIVERY_PIPELINE_URL]]])
      stash includes: '*.groovy', name: 'assets', useDefaultExcludes: false
      load './Jenkinsfile.groovy'
    }
    

    I used environment variables in case things need to change, probably could be even more dynamic than my example current (this is all still in development anyway).

    Then stash is used to hold the rest of the groovy scripts used later and unstash them in the declarative pipeline.

    Finally it loads the Declarative Pipeline. Doesn't mess with the views, basically all behaves normal.

    So it's not exactly what you were looking for, and I'd rather have the ability to just pull from SCM in the first place. But hey, it's been working well enough for me for the time being.

提交回复
热议问题