getBuildByNumber() returns null when build exists #489
Open
Description
opened on Sep 3, 2021
Jenkins version: Jenkins 2.277.1
Dependency Version: 0.3.8
I tried to get an old job number using getBuildByNumber()
:
Build build = jenkins.getJob(deployServicesJob).getBuildByNumber(buildNumber);
BuildWithDetails buildWithDetails = build.details();
Calling build.details();
throws:
java.lang.NullPointerException: Cannot invoke "com.offbytwo.jenkins.model.Build.details()" because "build" is null
The job has 200+ builds, which I suspect may be the problem if Jenkins only returns at most 100 jobs.
The build is accessible using getAllBuilds()
so my workaround is to use that method instead:
List<Build> allBuilds = jenkins.getJob(deployServicesJob).getAllBuilds();
Optional<Build> optional = allBuilds.stream().filter(b -> b.getNumber() == buildNumber).findFirst();
if (optional.isEmpty()) {
throw new IllegalArgumentException("Build not found");
}
Build build = optional.get();
Metadata
Assignees
Labels
No labels
Activity