jenkinsci / jenkinsci/gitlab-branch-source-plugin

[JENKINS-69221] Scan GitLab project fails on MR from private repository: 404 Project Not Found

Open
#711 2 comments 0 reactions 0 assignees View on GitHub
component:gitlab-branch-source-plugin imported-jira-issue priority:major resolution:unresolved
Dominant language
Java
Stars
134
Forks
113
PR merge metrics
No merged PRs in 30d

Description

Given a project configured as:

```
organizationFolder("Org1/Org2") {
organizations {
gitLabSCMNavigator {
projectOwner("Org1/Org2")
credentialsId("cee-gitlab-token")
serverName("cee-gitlab-server")
traits {
gitLabBranchDiscovery {
strategyId(3) // discover all branches
}
originMergeRequestDiscoveryTrait {
strategyId(1) // discover MRs and merge them with target branch
}
logComment {
logSuccess(true)
}
mrTriggerComment {
commentBody("jenkins rebuild")
onlyTrustedMembersCanTrigger(true)
}
}
}
}
// "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://issue-redirect.jenkins.io/issue/45504
configure {
def traits = it / navigators / 'io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator' / traits
traits << 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait' {
strategyId(2)
trust(class: 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$TrustPermission')
}
}

projectFactories {
workflowMultiBranchProjectFactory {
scriptPath 'Jenkinsfile'
}
}

// "Orphaned Item Strategy"
orphanedItemStrategy {
discardOldItems {
daysToKeep(10)
numToKeep(5)
}
}

// "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 {
interval('1d')
}
}
}

```

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.

---
Originally reported by olivergondza, imported from: Scan GitLab project fails on MR from private repository: 404 Project Not Found


  • assignee: baymac
  • status: Open
  • priority: Major
  • component(s): gitlab-branch-source-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 3
  • imported: 20251216-182730

Raw content of original issue

Given a project configured as:


organizationFolder("Org1/Org2") {

organizations {
gitLabSCMNavigator {
projectOwner("Org1/Org2")
credentialsId("cee-gitlab-token")
serverName("cee-gitlab-server")
traits {
gitLabBranchDiscovery {
strategyId(3) // discover all branches
}
originMergeRequestDiscoveryTrait {
strategyId(1) // discover MRs and merge them with target branch
}
logComment {
logSuccess(true)
}
mrTriggerComment {
commentBody("jenkins rebuild")
onlyTrustedMembersCanTrigger(true)
}
}
}
}
// "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' {
strategyId(2)
trust(class: 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$TrustPermission')
}
}

projectFactories {
workflowMultiBranchProjectFactory {
scriptPath 'Jenkinsfile'
}
}

// "Orphaned Item Strategy"
orphanedItemStrategy {
discardOldItems {
daysToKeep(10)
numToKeep(5)
}
}

// "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 {
interval('1d')
}
}
}


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.


Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.