jenkinsci / java-client-api

A Jenkins API client for Java
MIT License
896 stars 468 forks source link

getBuildByNumber() returns null when build exists #489

Open zhantt1 opened 2 years ago

zhantt1 commented 2 years ago

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();
XWTiger commented 2 years ago

maybe you can try use my repo that fork the master branch,i fix that bug

alexlogy commented 2 years ago

is this issue fixed? i'm facing the same issue..

XWTiger commented 2 years ago

is this issue fixed? i'm facing the same issue..

maybe you can see i forked repo

adnan1605 commented 1 year ago

hey , is anyone working on this issue?