Skip to content
Permalink
Browse files

[FIXED JENKINS-23946] Artifact Resolver failed to expand tokens

  • Loading branch information
imod committed Aug 16, 2014
1 parent d414aa3 commit 34e4846257fcde46e4ee314a8df7f700a3cb7075
@@ -179,7 +179,7 @@ private String checkVersionOverride(AbstractBuild<?, ?> build, BuildListener lis
for (ParametersAction parameterAction : parameterActionList) {
List<ParameterValue> parameterValueList = parameterAction.getParameters();
for (ParameterValue parameterValue : parameterValueList) {
if (ParameterValue.class.isAssignableFrom(VersionParameterValue.class)) {
if (parameterValue instanceof VersionParameterValue) {
VersionParameterValue versionParameterValue = (VersionParameterValue) parameterValue;
if (groupId != null && groupId.equals(versionParameterValue.getGroupid()) &&
artifactId != null && artifactId.equals(versionParameterValue.getArtifactid())) {
@@ -0,0 +1,116 @@
package org.jvnet.hudson.plugins.repositoryconnector;

import hudson.FilePath;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.Cause.UserCause;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.StringParameterDefinition;
import hudson.tasks.Builder;
import hudson.tasks.Shell;

import java.io.IOException;
import java.util.Collections;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class ArtifactDownloadTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void downloadWithFixVersionAndFixTargetDirAndTargetName() throws Exception {
j.jenkins.getInjector().injectMembers(this);

FreeStyleProject p = j.createFreeStyleProject();

Artifact a = new Artifact("commons-logging", "commons-logging", null, "1.0.4", "jar", "myJar.jar");
ArtifactResolver resolver = new ArtifactResolver("target", Collections.singletonList(a), true, false, "always", null, "always", null);

p.getBuildersList().add(resolver);
p.getBuildersList().add(new Shell("ls -ltr"));
p.getBuildersList().add(new VerifyBuilder("target/myJar.jar"));

j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, new UserCause()).get());
}


@Test
public void downloadWithFixVersionAndTargetName() throws Exception {
j.jenkins.getInjector().injectMembers(this);

FreeStyleProject p = j.createFreeStyleProject();

Artifact a = new Artifact("commons-logging", "commons-logging", null, "1.0", "jar", "myJar.jar");
ArtifactResolver resolver = new ArtifactResolver(null, Collections.singletonList(a), true, false, "always", null, "always", null);

p.getBuildersList().add(resolver);
p.getBuildersList().add(new VerifyBuilder("myJar.jar"));

j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, new UserCause()).get());
}

@Test
public void downloadWithFixVersion() throws Exception {
j.jenkins.getInjector().injectMembers(this);

FreeStyleProject p = j.createFreeStyleProject();

Artifact a = new Artifact("commons-logging", "commons-logging", null, "1.0.1", "jar", null);
ArtifactResolver resolver = new ArtifactResolver(null, Collections.singletonList(a), true, false, "always", null, "always", null);

p.getBuildersList().add(resolver);
p.getBuildersList().add(new VerifyBuilder("commons-logging-1.0.1.jar"));

j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, new UserCause()).get());
}

@Test
public void downloadWithVersionAsStringParameter() throws Exception {
j.jenkins.getInjector().injectMembers(this);

FreeStyleProject p = j.createFreeStyleProject();

Artifact a = new Artifact("${MY_ARTID}", "${MY_GROUP}", "${MY_CLASSIFIER}", "${MY_VERSION}", "${MY_EXT}", "${MY_FILE}");
ArtifactResolver resolver = new ArtifactResolver(null, Collections.singletonList(a), true, false, "always", null, "always", null);

p.getBuildersList().add(resolver);
p.getBuildersList().add(new VerifyBuilder("aFile.jar"));

// @formatter:off
ParametersDefinitionProperty parametersDefinitionProperty = new ParametersDefinitionProperty(new StringParameterDefinition("MY_VERSION", "1.0.4"),
new StringParameterDefinition("MY_ARTID", "commons-logging"),
new StringParameterDefinition("MY_GROUP", "commons-logging"),
new StringParameterDefinition("MY_CLASSIFIER", ""),
new StringParameterDefinition("MY_EXT", "jar"),
new StringParameterDefinition("MY_FILE", "aFile.jar"));
p.addProperty(parametersDefinitionProperty);
// @formatter:on

j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, new UserCause()).get());
}

private static final class VerifyBuilder extends Builder {

private final String expectedFile;

public VerifyBuilder(String expectedFile) {
this.expectedFile=expectedFile;
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath f = new FilePath(build.getWorkspace(), expectedFile);
Assert.assertTrue("File not available: " + f.getRemote(), f.exists());
return true;
}
}

}

0 comments on commit 34e4846

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