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

Fix Null pointer exceptions #161

Merged
merged 3 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ public NoFilesFoundEnum getNoFilesFoundAction() {
@Override
public List<AbstractBuildParameters> getParameters(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException, AbstractBuildParameters.DontTriggerException {
List<AbstractBuildParameters> result = Lists.newArrayList();

FilePath workspace = build.getWorkspace();
if (workspace == null) {
throw new IOException("Failed to get workspace");
}
try {
// save them into the master because FileParameterValue might need files after the slave workspace have disappeared/reused
FilePath target = new FilePath(build.getRootDir()).child("parameter-files");
int n = build.getWorkspace().copyRecursiveTo(getFilePattern(), target);
int n = workspace.copyRecursiveTo(getFilePattern(), target);

if (n==0) {
noFilesFoundAction.failCheck(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected QueueTaskFuture schedule(AbstractBuild<?, ?> build, Job project, List<
// it also means we have to force quiet period = 0, or else it'll never leave the queue
QueueTaskFuture f = schedule(build, project, 0, list, listener);
// When a project is disabled or the configuration is not yet saved f will always be null and we're caught in a loop, therefore we need to check for it
if (f!=null || (f==null && !canBeScheduled(project))){
if (f != null || !canBeScheduled(project)){
return f;
}
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import hudson.model.Result;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.CheckForNull;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -83,6 +84,7 @@ public boolean mapBuildStepResult(Result r) {
* @param r the {@link Result} of the triggered build to map
* @return the result of the triggering build
*/
@CheckForNull
public Result mapBuildResult(Result r) {
if (failureThreshold!=null && r.isWorseOrEqualTo(failureThreshold)) return FAILURE;
if (unstableThreshold!=null && r.isWorseOrEqualTo(unstableThreshold)) return UNSTABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,21 @@ private static void resolveProject(AbstractBuild build, SubProjectData subProjec
destinationSet = subProjectData.getDynamic();
}

final Jenkins jenkins = Jenkins.get();
Job resolvedProject = null;
try {
resolvedProject = jenkins == null ? null :
jenkins.getItem(unresolvedProjectName, build.getProject().getParent(), Job.class);
} catch (RuntimeException x) {
if (x.getClass().getSimpleName().startsWith("AccessDeniedException")) {
// Permission check failure (DISCOVER w/o READ) => we leave the job unresolved
} else {
throw x;
if (build != null) {
Job resolvedProject = null;
try {
resolvedProject = Jenkins.get().getItem(unresolvedProjectName, build.getProject().getParent(), Job.class);
} catch (RuntimeException x) {
if (x.getClass().getSimpleName().startsWith("AccessDeniedException")) {
// Permission check failure (DISCOVER w/o READ) => we leave the job unresolved
} else {
throw x;
}
}
if (resolvedProject != null) {
destinationSet.add(resolvedProject);
unsolvedProjectIterator.remove();
}
}
if (resolvedProject != null) {
destinationSet.add(resolvedProject);
unsolvedProjectIterator.remove();
}
}

Expand Down Expand Up @@ -645,9 +645,6 @@ protected QueueTaskFuture schedule(@Nonnull AbstractBuild<?, ?> build, @Nonnull
* @return
*/
private static String computeRelativeNamesAfterRenaming(String oldFullName, String newFullName, String relativeNames, ItemGroup<?> context) {
if(!Jenkins.getVersion().isOlderThan(new VersionNumber("1.530"))) {
return Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName, relativeNames, context);
}
StringTokenizer tokens = new StringTokenizer(relativeNames,",");
List<String> newValue = new ArrayList<>();
while(tokens.hasMoreTokens()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.DependencyGraph;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
Expand All @@ -51,6 +52,7 @@
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;

/**
* {@link Builder} that triggers other projects and optionally waits for their completion.
Expand All @@ -59,6 +61,8 @@
*/
public class TriggerBuilder extends Builder implements DependencyDeclarer {

private static final Logger LOGGER = Logger.getLogger(TriggerBuilder.class.getName());

private final ArrayList<BlockableBuildTriggerConfig> configs;

@DataBoundConstructor
Expand Down Expand Up @@ -133,9 +137,11 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
for (Job p : projectList) {
//handle non-buildable projects
if(!config.canBeScheduled(p)){
User user = User.current();
String userName = user != null ? ModelHyperlinkNote.encodeTo(user) : "unknown";
listener.getLogger().println("Skipping " + HyperlinkNote.encodeTo('/'+ p.getUrl(), p.getFullDisplayName()) +
". The project is either disabled,"
+ " or the authenticated user " + ModelHyperlinkNote.encodeTo(User.current()) + " has no Item.BUILD permissions,"
+ " or the authenticated user " + userName + " has no Item.BUILD permissions,"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the authenticated user unknown has no ..." is a bit odd, but should be ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be the authenticated user unknown has no Item.BUILD

+ " or the configuration has not been saved yet.");
continue;
}
Expand All @@ -151,7 +157,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildInfoExporterAction.addBuildInfoExporterAction(build, completedRun.getParent().getFullName(), completedRun.getNumber(), completedRun.getResult());

if (buildStepResult && config.getBlock().mapBuildStepResult(completedRun.getResult())) {
build.setResult(config.getBlock().mapBuildResult(completedRun.getResult()));
Result r = config.getBlock().mapBuildResult(completedRun.getResult());
if (r != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r == null when the run is not finished.
Maybe it makes sense to add a system warning for the edge case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I can add it in case there is some underlying issue here

build.setResult(r);
} else {
LOGGER.warning("Attempting to use the result of unfinished build " + completedRun.toString());
}
} else {
buildStepResult = false;
}
Expand Down