Skip to content

Commit

Permalink
[JENKINS-16028] [JENKINS-18762] Added tests to reproduce JENKINS-1602…
Browse files Browse the repository at this point in the history
…8 (environment variables are not set in maven prebuild), JENKINS-18762 (environment variables are not set when wrapped in another builder).
  • Loading branch information
ikedam committed Oct 1, 2014
1 parent a7ce03c commit 6ccfac8
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
69 changes: 68 additions & 1 deletion src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
Expand Up @@ -33,8 +33,11 @@
import hudson.matrix.TextAxis;
import hudson.matrix.MatrixRun;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.*;
import hudson.model.Cause.UserCause;
import hudson.plugins.copyartifact.testutils.FileWriteBuilder;
import hudson.plugins.copyartifact.testutils.WrapperBuilder;
import hudson.security.ACL;
import hudson.security.Permission;
import hudson.security.AuthorizationMatrixProperty;
Expand Down Expand Up @@ -150,7 +153,7 @@ private MatrixProject createMatrixArtifactProject() throws IOException {
return p;
}

private static void assertFile(boolean exists, String path, Build<?,?> b)
private static void assertFile(boolean exists, String path, AbstractBuild<?,?> b)
throws IOException, InterruptedException {
if (b.getWorkspace().child(path).exists() != exists)
assertEquals(path + ": " + getLog(b), exists, !exists);
Expand Down Expand Up @@ -898,6 +901,70 @@ public void testEnvData() throws Exception {
assertEquals("4", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_MY_TEST_JOB"));
}

@Bug(16028)
public void testEnvDataInMavenProject() throws Exception {
FreeStyleProject upstream = createFreeStyleProject("upstream");
upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false));
FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get();
assertBuildStatusSuccess(upstreamBuild);

MavenModuleSet downstream = setupMavenJob();
downstream.getPrebuilders().add(new CopyArtifact(
"upstream",
"",
new SpecificBuildSelector(Integer.toString(upstreamBuild.getNumber())),
"**/*",
"",
"",
false,
false,
false
));
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
downstream.getPrebuilders().add(envStep);

MavenModuleSetBuild downstreamBuild = downstream.scheduleBuild2(0).get();
assertBuildStatusSuccess(downstreamBuild);
assertFile(true, "artifact.txt", downstreamBuild);
assertEquals(
Integer.toString(upstreamBuild.getNumber()),
envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM")
);
}

@Bug(18762)
public void testEnvDataWrapped() throws Exception {
FreeStyleProject upstream = createFreeStyleProject("upstream");
upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false));
FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get();
assertBuildStatusSuccess(upstreamBuild);

FreeStyleProject downstream = createFreeStyleProject();
downstream.getBuildersList().add(new WrapperBuilder(new CopyArtifact(
"upstream",
"",
new SpecificBuildSelector(Integer.toString(upstreamBuild.getNumber())),
"**/*",
"",
"",
false,
false,
false
)));
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
downstream.getBuildersList().add(envStep);

FreeStyleBuild downstreamBuild = downstream.scheduleBuild2(0).get();
assertBuildStatusSuccess(downstreamBuild);
assertFile(true, "artifact.txt", downstreamBuild);
assertEquals(
Integer.toString(upstreamBuild.getNumber()),
envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM")
);
}

/**
* Test filtering on parameters, ie. last stable build with parameter FOO=bar.
*/
Expand Down
@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Copyright (c) 2014 IKEDA Yasuyuki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.plugins.copyartifact.testutils;

import java.io.IOException;

import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.tasks.Builder;

/**
* A builder wraps another buillder.
*/
public class WrapperBuilder extends Builder {
private final Builder builder;

public WrapperBuilder(Builder builder) {
this.builder = builder;
}

public Builder getBuilder() {
return builder;
}

@Override
public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
return builder.prebuild(build, listener);
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
return builder.perform(build, launcher, listener);
}
}

0 comments on commit 6ccfac8

Please sign in to comment.