Search code examples
jenkinsjenkins-pipelinejenkins-job-dsl

Can jenkins Pipeline force storing everything in VCS?


I have used Jenkins DSL. Now I started a new project and considering using Pipeline instead Jenkins DSL.

When using Jenkins DSL there was a seed job and everybody was forced to store every job in version control in order to not have it overwritten. I cannot find a way for forcing the same thing with Pipeline.

I liked this approach, because in my opinion it really helps to store everything in VCS.


Solution

  • When using Pipeline, you need to create the job configuration manually like the Job DSL seed job.

    You can use a mixed approach by using Job DSL for creating the Pipeline jobs and keep the pipeline definition in a Jenkinsfile next to your project's code.

    pipelineJob('example') {
      definition {
        cpsScm {
          scm {
            git('https://github.com/jenkinsci/job-dsl-plugin.git')
          }
          scriptPath('Jenkinsfile')
        }
      }
    }
    

    See https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob for details.

    Also checkout the advanced Pipeline job types like Multibranch and Organization Folder which provide a dynamic job setup out-of-the-box. See https://jenkins.io/doc/book/pipeline/multibranch/. The job types are also supported by Job DSL.