jenkinsci / jenkinsci/gitlab-plugin
badges are not applied because 'current' repository detection is wrong when loading library dynamically
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 615
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 10
Description
### Jenkins and plugins versions report
Environment
```text
Jenkins: 2.387.3
gitlab-plugin:1.7.14
```
### What Operating System are you using (both controller, and any agents involved in the problem)?
Linux Ubuntu 20.04
### Reproduction steps
In a multibranch pipeline:
1. Load a library dynamically with `library` method
2. checkout git repository with jenkins `git` method
3. try to set badges on repository using `gitlabBuilds` and/or `gitlabCommitStatus`
```
//configure gitlab connection
properties([
gitLabConnection("mygitlab"),
])
//dynamic load of library ! (this is different from @Library)
library "mylibraryidentifier@master"
node() {
//checkout my product's repository => doing this should result in setting commit status badges on this repository/commit on further operations
git credentialsId: 'xxxxxxxxxxxxxxxxxxx', url: "https://my_gitlab_repository.git", branch: env.BRANCH_NAME
gitlabBuilds(builds: ["test1","test2","test3"]) { //should set 'pending' commit status badges in my_gitlab_repository
sleep 5
gitlabCommitStatus(name: 'test1') { //should update 'test1' commit status badge in my_gitlab_repository
echo 'this is pre-build stage'
sleep 5
}
gitlabCommitStatus(name: 'test2') { //should update 'test2' commit status badge in my_gitlab_repository
echo 'this is build stage'
sleep 5
}
}
}
```
### Expected Results
All commit statuses should be successfully set on previously checked out repository : "my_gitlab_repository"
### Actual Results
this is my library repository that receives all commit statuses
### Anything else?
- Disabling the library dynamic load instruction gets back to the expected behavior.
- It seems that there is a wrong consideration of multiple repositories (library repository + my_gitlab_repository) in the plugin when defining the target of commit statuses
- this is confirmed by plugin logs showing that considered url is not the expected one 'my_gitlab_repository':
```
Aug 31, 2023 11:29:14 AM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Aug 31, 2023 11:29:14 AM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater addGitLabBranchBuild
Retrieving the gitlab project id from remote url [my library repository url]
```
I suspect that it could be related to this code, not considering the right SCM information: https://github.com/jenkinsci/gitlab-plugin/blob/6f6f22adecb232eead1a50fcac3fb6babae0c0e2/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java#L208
As stated in https://github.com/jenkinsci/gitlab-plugin/issues/899#issuecomment-588522480, a workaround is available to enforce `gitlabCommitStatus` to the right repository but this workaround is unfortunately not possible on `gitlabBuilds` method.
(It would also be acceptable to be able to set specific target repository when calling 'gitlabBuilds' as a workaround)
Thanks for your help on this.
Contributor guide
Assessment
This issue has not been assessed yet.