remote-file-plugin
remote-file-plugin copied to clipboard
Scan for branches fails after pipeline creation by JobDSL
Describe the bug Scan for branches fails after pipeline creation by JobDSL job.
To Reproduce Steps to reproduce the behavior:
- Create a pipeline by JobDSL job
- Go to the pipeline
- Push the button ('Scan Multibranch Pipeline Now')
- Take a look into the log of the scan and see java.lang.NullPointerException
Workaround Go to Configure and push Save button without any changes.
Log
Fri Dec 17 11:08:25 UTC 2021] Starting branch indexing...
> git --version # timeout=10
> git --version # 'git version 2.25.1'
using GIT_ASKPASS to set credentials service-user
> git ls-remote --symref -- <REPOSITORY_URL> # timeout=10
> git rev-parse --resolve-git-dir /var/lib/jenkins/caches/git-fe9dc345026856a1354c034869a81bf1/.git # timeout=10
Setting origin to <REPOSITORY_URL>
> git config remote.origin.url <REPOSITORY_URL> # timeout=10
Fetching & pruning origin...
Listing remote references...
> git config --get remote.origin.url # timeout=10
> git --version # timeout=10
> git --version # 'git version 2.25.1'
using GIT_ASKPASS to set credentials service-user
> git ls-remote -h -- <REPOSITORY_URL> # timeout=10
Fetching upstream changes from origin
> git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials service-user
> git fetch --tags --force --progress --prune -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking branches...
Checking branch <BRANCH_1>
No local file defined. Skipping Source Code SCM probe, since Jenkinsfile will be provided by Remote Jenkins File Plugin
Met criteria
ERROR: [Fri Dec 17 11:08:26 UTC 2021] Could not fetch branches from source 1
[Fri Dec 17 11:08:26 UTC 2021] Finished branch indexing. Indexing took 0.49 sec
FATAL: Failed to recompute children of Folder » Pipeline
java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.multibranch.extended.RemoteJenkinsFileWorkflowBranchProjectFactory.createDefinition(RemoteJenkinsFileWorkflowBranchProjectFactory.java:97)
at org.jenkinsci.plugins.workflow.multibranch.AbstractWorkflowBranchProjectFactory.setBranch(AbstractWorkflowBranchProjectFactory.java:63)
at org.jenkinsci.plugins.workflow.multibranch.AbstractWorkflowBranchProjectFactory.newInstance(AbstractWorkflowBranchProjectFactory.java:54)
at org.jenkinsci.plugins.workflow.multibranch.AbstractWorkflowBranchProjectFactory.newInstance(AbstractWorkflowBranchProjectFactory.java:44)
at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observeNew(MultiBranchProject.java:2055)
at jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observe(MultiBranchProject.java:1986)
at jenkins.scm.api.trait.SCMSourceRequest.process(SCMSourceRequest.java:357)
at jenkins.plugins.git.AbstractGitSCMSource$8.discoverBranches(AbstractGitSCMSource.java:705)
at jenkins.plugins.git.AbstractGitSCMSource$8.run(AbstractGitSCMSource.java:609)
at jenkins.plugins.git.AbstractGitSCMSource$8.run(AbstractGitSCMSource.java:588)
at jenkins.plugins.git.AbstractGitSCMSource.doRetrieve(AbstractGitSCMSource.java:394)
at jenkins.plugins.git.AbstractGitSCMSource.doRetrieve(AbstractGitSCMSource.java:350)
at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:588)
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:432)
Finished: FAILURE
JobDSL code
branchSources {
git {
id('1')
remote('<CODE_REPOSITORY_URL>')
credentialsId('service-user')
}
}
factory {
remoteJenkinsFileWorkflowBranchProjectFactory{
localMarker('')
remoteJenkinsFile('folder/subfolder/Jenkinsfile.groovy')
remoteJenkinsFileSCM{
gitSCM{
userRemoteConfigs{
userRemoteConfig{
name('origin')
url('<JENKINSFILES_REPOSITORY_URL>')
refspec('')
credentialsId('service-user')
}
browser{
gitLab {
repoUrl('<REPOSITORY_URL>')
}
}
gitTool('')
}
}
}
}
}
orphanedItemStrategy {
discardOldItems {
daysToKeep(90)
}
}
Expected behavior A repository can be scanned for branches right after creation by JobDSL.
Versions Jenkins 2.319.1 Job DSL 1.78.1 Remote Jenkinsfile Provider 1.21
I added a few more options to the JobDSL config:
fallbackBranch('master')
matchBranches(false)
lookupInParameters(false)
and it fixed the problem, looks like.
Anyway, it's not ok when one can't rely on default values.
Had the same issue. set these: matchBranches(false) lookupInParameters(false)
Reference to code changes: https://github.com/jenkinsci/remote-file-plugin/commit/746f980c889433a8e8db8ec575e4c0da4645de06#diff-e1c036b87383d3592d0b18b391cf129ade08bd8d01bc89ea42d6bcd251ec0466
@aytuncbeken Also hit this today using after a recent jenkins upgrade (including this plugin).
java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.multibranch.extended.RemoteJenkinsFileWorkflowMultiBranchProjectFactory.getMatchBranches(RemoteJenkinsFileWorkflowMultiBranchProjectFactory.java:178)
at org.jenkinsci.plugins.workflow.multibranch.extended.RemoteJenkinsFileWorkflowMultiBranchProjectFactory.customize(RemoteJenkinsFileWorkflowMultiBranchProjectFactory.java:160)
at org.jenkinsci.plugins.workflow.multibranch.AbstractWorkflowMultiBranchProjectFactory.doCreateProject(AbstractWorkflowMultiBranchProjectFactory.java:51)
at org.jenkinsci.plugins.workflow.multibranch.AbstractWorkflowMultiBranchProjectFactory.doCreateProject(AbstractWorkflowMultiBranchProjectFactory.java:46)
at jenkins.branch.MultiBranchProjectFactory$BySCMSourceCriteria.createNewProject(MultiBranchProjectFactory.java:235)
at jenkins.branch.OrganizationFolder$SCMSourceObserverImpl$1.completeNew(OrganizationFolder.java:1451)
at jenkins.branch.OrganizationFolder$SCMSourceObserverImpl$1.complete(OrganizationFolder.java:1395)
at jenkins.scm.api.trait.SCMNavigatorRequest.process(SCMNavigatorRequest.java:254)
at jenkins.scm.api.trait.SCMNavigatorRequest.process(SCMNavigatorRequest.java:204)
at com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator.visitSources(BitbucketSCMNavigator.java:501)
at jenkins.scm.api.SCMNavigator.visitSources(SCMNavigator.java:221)
at jenkins.branch.OrganizationFolder$SCMEventListenerImpl.onSCMHeadEvent(OrganizationFolder.java:1051)
at jenkins.scm.api.SCMHeadEvent$DispatcherImpl.fire(SCMHeadEvent.java:246)
at jenkins.scm.api.SCMHeadEvent$DispatcherImpl.fire(SCMHeadEvent.java:229)
at jenkins.scm.api.SCMEvent$Dispatcher.run(SCMEvent.java:546)
at jenkins.security.ImpersonatingScheduledExecutorService$1.run(ImpersonatingScheduledExecutorService.java:67)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
@gesundes - Thanks for documenting the workaround. That fixed it for me too, (but agree it should 'just work').
I also faced with it on https://github.com/jenkinsci/remote-file-plugin/releases/tag/remote-file-1.23 Even though the attribute already has a default value https://github.com/jenkinsci/remote-file-plugin/blob/11ac27face37b026b783c393232381a8c2dfac8c/src/main/java/org/jenkinsci/plugins/workflow/multibranch/extended/RemoteJenkinsFileWorkflowMultiBranchProjectFactory.java#L29-L30
I also faced the issue ?