[JENKINS-52307] fix npe with empty matrix projects (#1768)
* [JENKINS-52307] fix npe with empty matrix projects Signed-off-by: olivier lamy <olamy@apache.org>
This commit is contained in:
parent
1c8705b18e
commit
9229c889e2
|
@ -1,9 +1,5 @@
|
|||
package io.jenkins.blueocean.rest.impl.pipeline;
|
||||
|
||||
/**
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.matrix.MatrixProject;
|
||||
import hudson.model.Item;
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.Issue;
|
||||
import org.kohsuke.stapler.AcceptHeader;
|
||||
import org.kohsuke.stapler.export.Exported;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
|
@ -289,6 +290,14 @@ public class PipelineApiTest extends PipelineBaseTest {
|
|||
Assert.assertEquals("/job/mp1/", href);
|
||||
}
|
||||
|
||||
@Issue("JENKINS-52307")
|
||||
@Test
|
||||
public void matrixProjectEmptyBuild() throws Exception{
|
||||
MatrixProject mp = j.jenkins.createProject(MatrixProject.class, "mp1");
|
||||
List response = get("/organizations/jenkins/pipelines/", List.class);
|
||||
Assert.assertNotNull( response );
|
||||
}
|
||||
|
||||
@ExportedBean
|
||||
public static class TestAction implements Action {
|
||||
@Override
|
||||
|
|
|
@ -78,6 +78,14 @@ public class RestartStageTest extends PipelineBaseTest
|
|||
// depending on build still in queue or not when guessing the build number
|
||||
assertTrue( id >= r.getNumber());
|
||||
|
||||
// wait until the build get started
|
||||
r = p.getBuildByNumber( 2 );
|
||||
while(r==null){
|
||||
Thread.sleep( 100 );
|
||||
r = p.getBuildByNumber( 2 );
|
||||
}
|
||||
j.waitForCompletion( r );
|
||||
|
||||
runResult = get( "/organizations/jenkins/pipelines/" + p.getName() + "/runs/2");
|
||||
while (runResult.get( "state" ).equals( "RUNNING" )) {
|
||||
runResult = get( "/organizations/jenkins/pipelines/" + p.getName() + "/runs/2");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.jenkins.blueocean.service.embedded.rest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import hudson.Extension;
|
||||
import hudson.model.AbstractItem;
|
||||
import hudson.model.Item;
|
||||
|
@ -185,15 +185,17 @@ public class PipelineFolderImpl extends BluePipelineFolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "getPipelines() can definitely be null see MatrixProjectImpl so findbugs is wrong...")
|
||||
public Iterable<String> getPipelineFolderNames() {
|
||||
return Iterables.transform(getPipelines(), new Function<BluePipeline, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable BluePipeline input) {
|
||||
if (input != null && input instanceof BluePipelineFolder) {
|
||||
return input.getName();
|
||||
}
|
||||
return null;
|
||||
BluePipelineContainer bluePipelineContainer = getPipelines();
|
||||
if(bluePipelineContainer==null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Iterables.transform(bluePipelineContainer, input -> {
|
||||
if (input != null && input instanceof BluePipelineFolder) {
|
||||
return input.getName();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue