0

I am configuring Jenkins 2.332.3 with JCasC and the Multibranch pipeline. The pipeline is generally OK but it requires that we click This folder is empty | Configure the Project and then Save for it to recognise any jobs when the jenkins instance is first initialised!

Expected behaviour: When the kubernetes pod is initialised and Jenkins fires up for the first time, it should automatically effect the configured multibranch pipeline, instantiating the jobs. It should NOT show the "This folder is empty | Configure the Project" web page and the project should already have been "saved".

Any ideas on how to enable auto-configure of the multibranch project will be well appreciated.

Our JCasC code is below:

jobs: |
    jobs:
      - script: >
          organizationFolder('Xobabia Organisation') {
            buildStrategies {
                skipInitialBuildOnFirstBranchIndexing()
            }
            description("Xobabia Organisation")
            displayName('Xobabia Organisation')
            // "Projects"
            organizations {
              bitbucket {
                serverUrl("https://xobabia.com")
                repoOwner("xobabia")
                credentialsId("${XOBABIA_SECRET_BITBUCKET_APP_CREDS_USERNAME}")
                // "Traits" ("Behaviours" in the GUI) that are "declarative-compatible"
                // traits {
                //  webhookRegistrationTrait {
                //    mode('ITEM')
                //  }
                //}
              }
            }
            // "Traits" ("Behaviours" in the GUI) that are NOT "declarative-compatible"
            // For some 'traits, we need to configure this stuff by hand until JobDSL handles it
            // https://issues.jenkins.io/browse/JENKINS-45504
            configure { node ->
                def traits = node / navigators / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / traits
                // Filter by name (with regular expression)
                traits << 'jenkins.scm.impl.trait.RegexSCMSourceFilterTrait' {
                    regex('infra-k8s-namespaces-and-quotas|infra-jenkins-tests|infra-aws-iam|infra-docker|infra-k8s-rbac|infra-terraform-keycloak')
                }
                // Discover branches
                traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
                    strategyId('1')
                    // Values
                    //  1 : Exclude branches that are also filed as PRs
                    //  2 : Only branches that are also filed as PRs
                    //  3 : All branches
                }
                traits << 'com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait' {
                    credentialsId('bitbucket-ssh')
                }
                // Discover pull requests from origin
                traits << 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
                    strategyId('1')
                    // Values
                    // 1 : Merging the pull request with the current target branch revision
                    // 2 : The current pull request revision
                    // 3 : Both the current pull request revision and the pull request merged with the current target branch revision
                }
                // Discover pull requests from forks
                traits << 'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait' {
                    strategyId('1')
                    // Values
                    // 1 : Merging the pull request with the current target branch revision
                    // 2 : The current pull request revision
                    // 3 : Both the current pull request revision and the pull request merged with the current target branch revision
                    trustID('2')
                    // Values
                    // 0 : Everyone
                    // 1 : Forks in the same account
                    // 2 : Nobody
                }
            }
            // "Project Recognizers"
            projectFactories {
                workflowMultiBranchProjectFactory {
                    scriptPath 'Jenkinsfile'
                }
            }
            // "Orphaned Item Strategy"
            orphanedItemStrategy {
              discardOldItems {
                daysToKeep(10)
                numToKeep(10)
              }
            }
            // "Scan Organization Folder Triggers" : 1 day
            // We need to configure this stuff by hand because JobDSL only allow 'periodic(int min)' for now
            configure { node ->
              node / triggers / 'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger' {
                spec('H H * * *')
                interval(86400000)
              }
            }
          }

Many Thanks

Banoona
  • 103
  • 3

0 Answers0