Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getBuildByNumber() returns null when build exists #489

Open
zhantt1 opened this issue Sep 3, 2021 · 4 comments
Open

getBuildByNumber() returns null when build exists #489

zhantt1 opened this issue Sep 3, 2021 · 4 comments

Comments

@zhantt1
Copy link

zhantt1 commented 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();
@XWTiger
Copy link

XWTiger commented Sep 7, 2021

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

@alexlogy
Copy link

alexlogy commented Nov 5, 2021

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

@XWTiger
Copy link

XWTiger commented Nov 5, 2021

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

maybe you can see i forked repo

@adnan1605
Copy link

hey , is anyone working on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants