Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-69221

Scan GitLab project fails on MR from private repository: 404 Project Not Found


      Given a project configured as:

      organizationFolder("Org1/Org2") {
          organizations {
              gitLabSCMNavigator {
                  traits {
                      gitLabBranchDiscovery {
                          strategyId(3) // discover all branches
                      originMergeRequestDiscoveryTrait {
                          strategyId(1) // discover MRs and merge them with target branch
                      logComment {
                      mrTriggerComment {
                          commentBody("jenkins rebuild")
          // "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 {
              def traits = it / navigators / 'io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator' / traits
              traits << 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait' {
                  trust(class: 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$TrustPermission')
          projectFactories {
              workflowMultiBranchProjectFactory {
                  scriptPath 'Jenkinsfile'
          // "Orphaned Item Strategy"
          orphanedItemStrategy {
              discardOldItems {
          // "Scan Organization Folder Triggers" : 1 day
          // We need to configure this stuff by hand because JobDSL only allow 'periodic(int min)' for now
          triggers {
              periodicFolderTrigger {

      Scanning for branches/MRs gets aborted on a first MR that is from a private repository. MRs from public forks and from that repository itself are detected correctly.

      Checking merge requests..
      Checking merge request !9
      ERROR: [Wed Aug 03 07:08:00 UTC 2022] Could not fetch branches from source io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator::https://gitlab.example.com::Org1/Org2::Org1/Org2/my-repo
      [Wed Aug 03 07:08:00 UTC 2022] Finished branch indexing. Indexing took 0.99 sec
      FATAL: Failed to recompute children of Org1 » Org2 » Org1/Org2/my-repo
      org.gitlab4j.api.GitLabApiException: 404 Project Not Found
          at org.gitlab4j.api.AbstractApi.validate(AbstractApi.java:633)
          at org.gitlab4j.api.AbstractApi.get(AbstractApi.java:213)
          at org.gitlab4j.api.ProjectApi.getProject(ProjectApi.java:673)
          at io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource.retrieve(GitLabSCMSource.java:417)
      Caused: java.io.IOException: Failed to fetch latest heads
          at io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource.retrieve(GitLabSCMSource.java:538)
          at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:373)
          at jenkins.scm.api.SCMSource.fetch(SCMSource.java:283)
          at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:641)
          at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:278)
          at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:166)
          at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1032)
          at hudson.model.ResourceController.execute(ResourceController.java:99)
          at hudson.model.Executor.run(Executor.java:431)
      Finished: FAILURE

      There are essentially 2 consequences:

      • None other MRs are discovered, even when they would not run into this bug. The scanning is aborted on first such MR.
      • There is no indication why exactly the MR cannot be discovered. The log points to the target repo, while the problem is in reading from the source one.

            baymac Parichay Barpanda
            olivergondza Oliver Gondža
            0 Vote for this issue
            2 Start watching this issue