Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5fb3d84
[JENKINS-49635] Support new VirtualFile.asRemotable API.
jglick Feb 28, 2018
7562986
Stash support.
jglick Mar 13, 2018
6ba60da
Updates.
jglick Mar 14, 2018
75b73bf
CI failure.
jglick Mar 14, 2018
a2abb37
useBeta
jglick Mar 26, 2018
781d409
Calling VirtualFile.toExternalURL rather than asRemotable.
jglick Apr 2, 2018
d323514
Picking up https://github.com/jenkinsci/plugin-pom/pull/98.
jglick Apr 3, 2018
b3a8a3c
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Apr 16, 2018
a01cdb6
Updated.
jglick Apr 16, 2018
c072ff8
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Apr 17, 2018
f44835b
requireUpperBoundDeps
jglick Apr 17, 2018
3959063
Merge branch 'master' into VirtualFile-JENKINS-49635
jglick Apr 23, 2018
d19b231
jenkins.version=2.118
jglick Apr 23, 2018
ce7a8ac
Consuming incrementals.
jglick Apr 27, 2018
2170267
Preparing to produce Incrementals.
jglick Apr 27, 2018
d2bd052
Linking also to https://github.com/jenkinsci/workflow-step-api-plugin…
jglick Apr 27, 2018
c9d28b0
Picking up https://github.com/jenkinsci/plugin-pom/pull/105.
jglick May 9, 2018
af6af8d
[JENKINS-51187] Moving git-changelist-maven-extension into incrementa…
jglick May 10, 2018
f9f8b16
Updates.
jglick May 11, 2018
c660832
Updated.
jglick May 16, 2018
eed2d6f
workflow-step-api-plugin.version=2.15
jglick May 21, 2018
ae43469
Using RobustHTTPClient utility for artifact downloads.
jglick Jun 5, 2018
5d47212
apache-httpcomponents-client-4-api 4.5.5-3.0
jglick Jun 13, 2018
d5baf3a
https://github.com/jenkinsci/workflow-api-plugin/pull/67 released.
jglick Jun 15, 2018
2e4d5d0
May as well use LTS also.
jglick Jun 15, 2018
5882dbd
Merge branch 'master' into VirtualFile-JENKINS-49635
svanoort Jun 15, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.2</version>
<version>3.5</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -62,11 +62,13 @@
</pluginRepository>
</pluginRepositories>
<properties>
<jenkins.version>2.7.3</jenkins.version>
<java.level>7</java.level>
<workflow-step-api-plugin.version>2.13</workflow-step-api-plugin.version>
<jenkins-core.version>2.110-20180228.232138-2</jenkins-core.version> <!-- TODO https://github.com/jenkinsci/jenkins/pull/3302 -->
<jenkins-war.version>2.110-20180228.232235-2</jenkins-war.version>
<java.level>8</java.level>
<workflow-step-api-plugin.version>2.15-20180228.225735-2</workflow-step-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-step-api-plugin/pull/33 -->
<workflow-cps-plugin.version>2.32</workflow-cps-plugin.version>
<workflow-support-plugin.version>2.14</workflow-support-plugin.version>
<workflow-api-plugin.version>2.27-20180228.232906-1</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
</properties>
<dependencies>
<dependency>
Expand All @@ -89,18 +91,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.16</version>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
</exclusion>
</exclusions>
<version>${workflow-api-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.6</version>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -194,5 +190,12 @@
<version>2.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>${workflow-api-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
import hudson.AbortException;
import hudson.FilePath;
import hudson.model.Run;
import jenkins.model.ArtifactManager;
import jenkins.util.VirtualFile;

import hudson.remoting.VirtualChannel;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import jenkins.MasterToSlaveFileCallable;
import jenkins.util.VirtualFile;

/**
* @author Kohsuke Kawaguchi
*/
public class ArtifactUnarchiverStepExecution extends SynchronousNonBlockingStepExecution<List<FilePath>> {
public class ArtifactUnarchiverStepExecution extends SynchronousNonBlockingStepExecution<Void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not binary compatible, needs to be Restricted at least


@SuppressFBWarnings(value="SE_TRANSIENT_FIELD_NOT_RESTORED", justification="Only used when starting.")
private transient final Map<String,String> mapping;
Expand All @@ -31,48 +28,74 @@ public class ArtifactUnarchiverStepExecution extends SynchronousNonBlockingStepE
}

@Override
protected List<FilePath> run() throws Exception {
protected Void run() throws Exception {
// where to copy artifacts from?
Run<?, ?> r = getContext().get(Run.class); // TODO consider an option to override this (but in what format?)

ArtifactManager am = r.getArtifactManager();
VirtualFile root = r.getArtifactManager().root();
FilePath target = getContext().get(FilePath.class);
if (target.isRemote()) {
VirtualFile rootR = root.asRemotable();
if (rootR != null) {
return target.act(new Copy(mapping, target, rootR));
} else {
return new Copy(mapping, target, root).invoke(null, null);
}
} else {
return new Copy(mapping, target, root).invoke(null, null);
}
}

private static class Copy extends MasterToSlaveFileCallable<Void> {

List<FilePath> files = new ArrayList<>();
private static final long serialVersionUID = 1L;

for (Entry<String, String> e : mapping.entrySet()) {
FilePath dst = new FilePath(getContext().get(FilePath.class), e.getValue());
String src = e.getKey();
String[] all = am.root().list(src);
if (all.length == 0) {
throw new AbortException("no artifacts to unarchive in " + src);
} else if (all.length == 1 && all[0].equals(src)) {
// the source is a file
if (dst.isDirectory())
dst = dst.child(getFileName(all[0]));
private final Map<String, String> _mapping;
private final FilePath target;
private final VirtualFile root;

files.add(copy(am.root().child(all[0]), dst));
} else {
// copy into a directory
for (String path : all) {
files.add(copy(am.root().child(path), dst.child(path)));
Copy(Map<String, String> _mapping, FilePath target, VirtualFile root) {
this._mapping = _mapping;
this.target = target;
this.root = root;
}

@Override public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
for (Entry<String, String> e : _mapping.entrySet()) {
FilePath dst = new FilePath(target, e.getValue());
String src = e.getKey();
Collection<String> all = root.list(src, null, false);
if (all.isEmpty()) {
throw new AbortException("no artifacts to unarchive in " + src);
} else if (all.size() == 1 && all.iterator().next().equals(src)) {
// the source is a file
if (dst.isDirectory()) {
dst = dst.child(getFileName(all.iterator().next()));
}

copy(root.child(all.iterator().next()), dst);
} else {
// copy into a directory
for (String path : all) {
copy(root.child(path), dst.child(path));
}
}
}
return null;
}

return files;
}

private FilePath copy(VirtualFile src, FilePath dst) throws IOException, InterruptedException {
private static void copy(VirtualFile src, FilePath dst) throws IOException, InterruptedException {
try (InputStream in = src.open()) {
dst.copyFrom(in);
}
return dst;
}

/**
* Grabs the file name portion out of a path name.
*/
private String getFileName(String s) {
private static String getFileName(String s) {
int idx = s.lastIndexOf('/');
if (idx>=0) s=s.substring(idx+1);
idx = s.lastIndexOf('\\');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package org.jenkinsci.plugins.workflow.steps;

import java.util.Arrays;
import jenkins.model.ArtifactManagerConfiguration;
import jenkins.util.VirtualFile;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.workflow.DirectArtifactManagerFactory;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Assert;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

/**
* @author Kohsuke Kawaguchi
*/
public class ArtifactArchiverStepTest extends Assert {
public class ArtifactArchiverStepTest {

@ClassRule public static BuildWatcher watcher = new BuildWatcher();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so that the test log includes the log from the build run at line 90.


@Rule public JenkinsRule j = new JenkinsRule();

/**
Expand Down Expand Up @@ -74,5 +78,15 @@ public void archive() throws Exception {
j.assertLogContains("one/two", b);
}

}
@Issue("JENKINS-49635")
@Test
public void directDownload() throws Exception {
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(new DirectArtifactManagerFactory());
j.createSlave("remote1", null, null);
j.createSlave("remote2", null, null);
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node('remote1') {writeFile file: 'x', text: 'contents'; archiveArtifacts 'x'}; node('remote2') {unarchive mapping: [x: 'x']; echo(/loaded ${readFile('x')}/)}", true));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no stash/unstash test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because that behavior is not being defined in this PR—it would be overridden in the plugin providing the ArtifactManagerFactory.

j.assertLogContains("loaded contents", j.buildAndAssertSuccess(p));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import hudson.model.Run;
import hudson.model.Slave;
import hudson.model.TaskListener;
import hudson.slaves.CommandLauncher;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;
Expand Down