Home > Blockchain >  Jenkins JCasC Defining All Projects as Code
Jenkins JCasC Defining All Projects as Code

Time:09-22

When you want to configure a jenkins instance as code in kubernetes you use helm and JCasC

When you write a jenkins pipeline you do it in a Jenkinsfile

But when you want to define a multi branch pipeline in Jenkins you have to click new item and multi branch pipeline and then do all those steps graphically.

Well I have like 30 multi branch pipelines and I would really like to define their settings as code as well.

What is this called, and is there any way to export this config from jenkins and then add it to JCasC?

CodePudding user response:

I guess you want to configure the mulitbranchPipeline in JCasC here the example to create a multibranch pipeline

     multibranchPipelineJob('Add your job name here'){
            branchSources {
                branchSource {
                    source {
                        git {
                            id = 'Add your job name here'
                            remote('Add you git repo.git')
                            credentialsId('')

                            traits {
                                gitBranchDiscovery()
                                gitTagDiscovery()
                            }
                        }
                    }
                    strategy {
                        defaultBranchPropertyStrategy {
                            props {
                                noTriggerBranchProperty()
                            }
                        }
                    }
                }
            }
            displayName('Add your job name here')
            orphanedItemStrategy { discardOldItems { numToKeep(-1) } }
        }

For more information please checkout docs https://jenkinsci.github.io/job-dsl-plugin/#

  • Related