Skip to content

Commit

Permalink
[JENKINS-30390] Use a workflow step to copy resources to the current …
Browse files Browse the repository at this point in the history
…workspace
  • Loading branch information
amuniz committed Oct 2, 2015
1 parent f206413 commit c0aeb6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/jenkinsci/test/acceptance/po/Job.java
Expand Up @@ -165,6 +165,10 @@ public ShellBuildStep addShellStep(String shell) {
* base64 and put it as a heredoc in the shell script.
*/
public void copyResource(Resource resource, String fileName) {
addShellStep(copyResourceShell(resource, fileName));
}

protected String copyResourceShell(Resource resource, String fileName) {
try (InputStream in = resource.asInputStream()) {
ByteArrayOutputStream out = new ByteArrayOutputStream();

Expand All @@ -173,8 +177,8 @@ public void copyResource(Resource resource, String fileName) {
}

// fileName can include path portion like foo/bar/zot
addShellStep(String.format("(mkdir -p %1$s || true) && rm -r %1$s && base64 --decode << ENDOFFILE | gunzip > %1$s \n%2$s\nENDOFFILE",
fileName, new String(Base64.encodeBase64Chunked(out.toByteArray()))));
return String.format("(mkdir -p %1$s || true) && rm -r %1$s && base64 --decode << ENDOFFILE | gunzip > %1$s \n%2$s\nENDOFFILE",
fileName, new String(Base64.encodeBase64Chunked(out.toByteArray())));
} catch (IOException e) {
throw new AssertionError(e);
}
Expand Down
Expand Up @@ -26,6 +26,7 @@

import com.google.inject.Injector;
import java.net.URL;
import org.jenkinsci.test.acceptance.junit.Resource;

@Describable("org.jenkinsci.plugins.workflow.job.WorkflowJob")
public class WorkflowJob extends Job {
Expand All @@ -37,4 +38,9 @@ public WorkflowJob(Injector injector, URL url, String name) {
public final Control script = control("/definition/script");
public final Control sandbox = control("/definition/sandbox");

public String copyResourceStep(String filePath) {
final Resource res = resource(filePath);
return String.format("sh '''%s'''%n", copyResourceShell(res, res.getName()));
}

}
17 changes: 6 additions & 11 deletions src/test/java/plugins/AnalysisCollectorPluginTest.java
Expand Up @@ -13,7 +13,6 @@
import org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleFreestyleSettings;
import org.jenkinsci.test.acceptance.plugins.dashboard_view.DashboardView;
import org.jenkinsci.test.acceptance.plugins.findbugs.FindBugsFreestyleSettings;
import org.jenkinsci.test.acceptance.plugins.maven.MavenInstallation;
import org.jenkinsci.test.acceptance.plugins.pmd.PmdFreestyleSettings;
import org.jenkinsci.test.acceptance.plugins.tasks.TasksFreestyleSettings;
import org.jenkinsci.test.acceptance.plugins.warnings.WarningsBuildSettings;
Expand Down Expand Up @@ -331,18 +330,14 @@ public void should_aggregate_warnings_in_dashboard_portlet() {
}

@Test
@WithPlugins({"git@2.4.0", "workflow-aggregator@1.10"})
@WithPlugins("workflow-aggregator")
public void should_compute_annotations_on_workflow() {
MavenInstallation.installMaven(jenkins, "M3", "3.3.3");
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
// TODO: Job.copyResource(String) does not work for WorkflowJob, since it does not owns
// a workspace but the build does (actually it could own 0..N workspaces).
job.script.set(
"node {\n" +
" git 'https://github.com/amuniz/maven-helloworld.git'\n" +
" def mvnHome = tool 'M3'\n" +
" sh \"${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify\"\n" +
" step([$class: 'FindBugsPublisher', pattern: '**/findbugsXml.xml'])\n" +
job.copyResourceStep(ANALYSIS_COLLECTOR_PLUGIN_RESOURCES + "/checkstyle-result.xml") +
job.copyResourceStep(ANALYSIS_COLLECTOR_PLUGIN_RESOURCES +"/findbugs.xml") +
" step([$class: 'FindBugsPublisher', pattern: '**/findbugs.xml'])\n" +
" step([$class: 'CheckStylePublisher'])\n" +
" step([$class: 'AnalysisPublisher'])\n" +
"}");
Expand All @@ -356,8 +351,8 @@ public void should_compute_annotations_on_workflow() {
AnalysisCollectorAction action = new AnalysisCollectorAction(build);
action.open();

assertThat(action.getNumberOfWarnings(), is(17)); // 1 from FB and 16 from CS
assertThat(action.getNumberOfNewWarnings(), is(17));
assertThat(action.getNumberOfWarnings(), is(FINDBUGS_ALL + CHECKSTYLE_ALL));
assertThat(action.getNumberOfNewWarnings(), is(FINDBUGS_ALL + CHECKSTYLE_ALL));
}

private AnalysisCollectorAction deselectPluginAndBuild(AnalysisPlugin plugin, Job job) {
Expand Down

0 comments on commit c0aeb6d

Please sign in to comment.