jenkinsci / configuration-as-code-plugin

Jenkins Configuration as Code Plugin
https://plugins.jenkins.io/configuration-as-code
MIT License
2.7k stars 720 forks source link

Jenkins is not starting in installation phase - bitbucket rate limiting error #2511

Open rnkhouse opened 5 months ago

rnkhouse commented 5 months ago

Description

Sometimes, jenkins is not starting and shutting down in organization folder scan step. I found out that getting rate limiting error from bitbucket server because of many requests from jenkins.

How can I make sure not to scan all branches when I start the instance. I am using below config:

organizationFolder('my-bitbucket') {
  description("Bitbucket org folder configured with JCasC")
  displayName('project')
  organizations {
    bitbucket {
      serverUrl("https://bitbucket.org")
      repoOwner("project")
      credentialsId("bitbucket")
    }
  }
  configure { node ->
      def traits = node / navigators / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / traits
      traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
          strategyId('1')
      }
      traits << 'jenkins.scm.impl.trait.WildcardSCMSourceFilterTrait' {
          includes('project1 project2 project3')
      }
      traits << 'jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait' {
          includes('alpha develop staging master')
      }
      traits << 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
          strategyId('1')
      }
      traits << 'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait' {
          strategyId('1')
          trustID('1')
      }
  }
  projectFactories {
      workflowMultiBranchProjectFactory {
          scriptPath 'Jenkinsfile'
      }
  }
  orphanedItemStrategy {
    discardOldItems {
      daysToKeep(-1)
      numToKeep(-1)
    }
  }
  buildStrategies {
    buildAllBranches {
      strategies {
        skipInitialBuildOnFirstBranchIndexing()
      }
    }
  }
}

Jenkins shutting down after logs like this:

2024-06-14 20:23:27.972+0000 [id=30] INFO c.c.h.p.folder.AbstractFolder#lambda$onLoad$4: Loading job bitbucket-cluster/project1 (593.3%)

These are the logs we got from bitbucket for rate limiting:

/2.0/repositories/My-project/project1/src/5e7647700b366aab5e254312fba0127757a7e0be/Jenkinsfile - 1034
/2.0/repositories/My-project/project1/pullrequests?page=1&pagelen=50 - 947
/2.0/repositories/My-project/project2/src/6dbba8a547047884f3aff794910abc522cc7e691/Jenkinsfile - 912
/2.0/repositories/My-project/project2/pullrequests?page=2&pagelen=50 - 346
/2.0/repositories/My-project/project2/pullrequests?page=1&pagelen=50 - 153
/2.0/repositories/My-project/project1/refs/branches/develop - 10

As you can see, it's hitting PRs and different branches those we don't even have in above config.