Skip to content
Permalink
Browse files

Merge pull request #92 from jenkinsci/JENKINS-30040-tests

[JENKINS-30040] Logging exception running triggering nonblocking builds
  • Loading branch information...
olivergondza committed Sep 10, 2015
2 parents 4898671 + bbccd61 commit 0e680b53b97f34289a2689a4f76dbb3c7e389b03
@@ -39,6 +39,7 @@
import hudson.model.Job;
import hudson.model.Run;
import hudson.util.IOException2;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
@@ -157,10 +158,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
return buildStepResult;
}

private String getProjectListAsString(List<Job> projectList){
// Public but restricted so we can add tests without completely changing the tests package
@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class)
public String getProjectListAsString(List<Job> projectList){
StringBuilder projectListString = new StringBuilder();
for (Iterator iterator = projectList.iterator(); iterator.hasNext();) {
AbstractProject project = (AbstractProject) iterator.next();
for (Iterator<Job> iterator = projectList.iterator(); iterator.hasNext();) {
Job project = iterator.next();
projectListString.append(HyperlinkNote.encodeTo('/'+ project.getUrl(), project.getFullDisplayName()));
if(iterator.hasNext()){
projectListString.append(", ");
@@ -45,6 +45,7 @@
import hudson.matrix.AxisList;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
@@ -58,6 +59,7 @@
import java.lang.System;

import jenkins.model.Jenkins;
import org.jvnet.hudson.test.Issue;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -235,6 +237,25 @@ public void testTriggerWithWorkflow() throws Exception {
assertNotNull(p.getLastBuild());
}

/** Verify that getProjectsList works with workflow and normal projects */
@Issue("JENKINS-30040")
public void testGetProjectsList() throws Exception {
WorkflowJob p = (WorkflowJob) Jenkins.getInstance().createProject(WorkflowJob.class, "project1");
p.setDefinition(new CpsFlowDefinition("println('hello')"));
Project<?, ?> p2 = createFreeStyleProject("project2");

Project<?, ?> triggerProject = createFreeStyleProject("projectA");
TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("project1"));
triggerProject.getBuildersList().add(triggerBuilder);

List<Job> jobs = new ArrayList<Job>();
jobs.add(p);
jobs.add(p2);
String projectListAsString = triggerBuilder.getProjectListAsString(jobs);
assertStringContains(projectListAsString, "project1");
assertStringContains(projectListAsString, "project2");
}

/** Verify that workflow build can be triggered with normal project too */
public void testTriggerWithWorkflowMixedTypes() throws Exception {
createFreeStyleProject("project1");

0 comments on commit 0e680b5

Please sign in to comment.
You can’t perform that action at this time.