Skip to content

Commit 9b957b5

Browse files
committed
Using OutboundAgent
1 parent f606866 commit 9b957b5

File tree

3 files changed

+30
-71
lines changed

3 files changed

+30
-71
lines changed

pom.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,22 @@
7474
<dependency>
7575
<groupId>io.jenkins.tools.bom</groupId>
7676
<artifactId>bom-${jenkins.baseline}.x</artifactId>
77-
<version>4948.vcf1d17350668</version>
77+
<version>5015.vb_52d36583443</version>
7878
<scope>import</scope>
7979
<type>pom</type>
8080
</dependency>
81+
<!-- TODO https://github.com/jenkinsci/ssh-agents-plugin/pull/607 -->
82+
<dependency>
83+
<groupId>org.jenkins-ci.plugins</groupId>
84+
<artifactId>ssh-slaves</artifactId>
85+
<version>3.1069.v30991b_9a_4f68</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.jenkins-ci.plugins</groupId>
89+
<artifactId>ssh-slaves</artifactId>
90+
<classifier>tests</classifier>
91+
<version>3.1069.v30991b_9a_4f68</version>
92+
</dependency>
8193
</dependencies>
8294
</dependencyManagement>
8395
<dependencies>
@@ -133,6 +145,17 @@
133145
<artifactId>ssh-slaves</artifactId>
134146
<scope>test</scope>
135147
</dependency>
148+
<dependency>
149+
<groupId>org.jenkins-ci.plugins</groupId>
150+
<artifactId>ssh-slaves</artifactId>
151+
<classifier>tests</classifier>
152+
<scope>test</scope>
153+
</dependency>
154+
<dependency>
155+
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
156+
<artifactId>mina-sshd-api-common</artifactId>
157+
<scope>test</scope>
158+
</dependency>
136159
<dependency>
137160
<groupId>org.jenkins-ci.plugins</groupId>
138161
<artifactId>apache-httpcomponents-client-4-api</artifactId>

src/test/java/org/jenkinsci/plugins/workflow/ArtifactManagerTest.java

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*d
22
* The MIT License
33
*
44
* Copyright 2018 CloudBees, Inc.
@@ -35,11 +35,6 @@
3535
import static org.junit.Assert.assertTrue;
3636
import static org.junit.Assert.fail;
3737

38-
import com.cloudbees.plugins.credentials.CredentialsProvider;
39-
import com.cloudbees.plugins.credentials.CredentialsScope;
40-
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
41-
import com.cloudbees.plugins.credentials.domains.Domain;
42-
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
4338
import hudson.AbortException;
4439
import hudson.EnvVars;
4540
import hudson.ExtensionList;
@@ -50,7 +45,6 @@
5045
import hudson.model.FreeStyleBuild;
5146
import hudson.model.FreeStyleProject;
5247
import hudson.model.TaskListener;
53-
import hudson.plugins.sshslaves.SSHLauncher;
5448
import hudson.remoting.Callable;
5549
import hudson.slaves.DumbSlave;
5650
import hudson.tasks.ArtifactArchiver;
@@ -67,20 +61,16 @@
6761
import jenkins.model.ArtifactManager;
6862
import jenkins.model.ArtifactManagerConfiguration;
6963
import jenkins.model.ArtifactManagerFactory;
70-
import jenkins.model.Jenkins;
7164
import jenkins.model.StandardArtifactManager;
7265
import jenkins.security.MasterToSlaveCallable;
7366
import jenkins.util.VirtualFile;
7467
import org.apache.commons.io.IOUtils;
7568
import org.jenkinsci.plugins.workflow.flow.StashManager;
76-
import org.junit.BeforeClass;
7769
import org.junit.Rule;
7870
import org.junit.Test;
7971
import org.jvnet.hudson.test.JenkinsRule;
8072
import org.jvnet.hudson.test.LoggerRule;
81-
import org.testcontainers.DockerClientFactory;
82-
import org.testcontainers.containers.GenericContainer;
83-
import org.testcontainers.images.builder.ImageFromDockerfile;
73+
import test.ssh_agent.OutboundAgent;
8474

8575
/**
8676
* {@link #artifactArchiveAndDelete} and variants allow an implementation of {@link ArtifactManager} plus {@link VirtualFile} to be run through a standard gantlet of tests.
@@ -90,23 +80,6 @@ public class ArtifactManagerTest {
9080
@Rule public JenkinsRule r = new JenkinsRule();
9181
@Rule public LoggerRule logging = new LoggerRule();
9282

93-
private static GenericContainer<?> container;
94-
95-
@BeforeClass public static void doPrepareImage() {
96-
container = prepareImage();
97-
}
98-
99-
public static @CheckForNull GenericContainer<?> prepareImage() {
100-
if (!Functions.isWindows() && DockerClientFactory.instance().isDockerAvailable()) { // TODO: Windows agents on ci.jenkins.io have Docker, but cannot build the image.
101-
return new GenericContainer<>(new ImageFromDockerfile("java17-ssh", false)
102-
.withFileFromClasspath("Dockerfile", ArtifactManagerTest.class.getName().replace('.', '/') + "/Dockerfile"))
103-
.withExposedPorts(22);
104-
} else {
105-
System.err.println("No Docker support; falling back to running tests against an agent in a process on the same machine.");
106-
return null;
107-
}
108-
}
109-
11083
/**
11184
* Creates an agent, in a Docker container when possible, calls {@link #setUpWorkspace}, then runs some tests.
11285
*/
@@ -115,18 +88,10 @@ private static void wrapInContainer(@NonNull JenkinsRule r, @CheckForNull Artifa
11588
if (factory != null) {
11689
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(factory);
11790
}
118-
try {
119-
DumbSlave agent;
120-
if (container != null) {
121-
container.start();
122-
StandardUsernameCredentials creds = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, "test", "desc", "test", "test");
123-
CredentialsProvider.lookupStores(Jenkins.get()).iterator().next().addCredentials(Domain.global(), creds);
124-
agent = new DumbSlave("test-agent", "/home/test/slave", new SSHLauncher(container.getHost(), container.getMappedPort(22), "test"));
125-
Jenkins.get().addNode(agent);
126-
r.waitOnline(agent);
127-
} else {
128-
agent = r.createOnlineSlave();
129-
}
91+
try (var outboundAgent = new OutboundAgent()) {
92+
OutboundAgent.createAgent(r, "remote", outboundAgent.start());
93+
var agent = (DumbSlave) r.jenkins.getNode("remote");
94+
r.waitOnline(agent);
13095
FreeStyleProject p = r.createFreeStyleProject();
13196
p.setAssignedNode(agent);
13297
FilePath ws = agent.getWorkspaceFor(p);
@@ -136,10 +101,6 @@ private static void wrapInContainer(@NonNull JenkinsRule r, @CheckForNull Artifa
136101
p.getPublishersList().add(aa);
137102
FreeStyleBuild b = r.buildAndAssertSuccess(p);
138103
f.apply(agent, p, b, ws);
139-
} finally {
140-
if (container != null) {
141-
container.stop();
142-
}
143104
}
144105
}
145106

src/test/resources/org/jenkinsci/plugins/workflow/ArtifactManagerTest/Dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)