hudson.plugins.sshslaves.SSHLauncher Java Examples
The following examples show how to use
hudson.plugins.sshslaves.SSHLauncher.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntegrationTest.java From warnings-ng-plugin with MIT License | 6 votes |
@SuppressWarnings({"PMD.AvoidCatchingThrowable", "IllegalCatch"}) protected DumbSlave createDockerContainerAgent(final DockerContainer dockerContainer) { try { SystemCredentialsProvider.getInstance().getDomainCredentialsMap().put(Domain.global(), Collections.singletonList( new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, "dummyCredentialId", null, "test", "test") ) ); DumbSlave agent = new DumbSlave("docker", "/home/test", new SSHLauncher(dockerContainer.ipBound(22), dockerContainer.port(22), "dummyCredentialId")); agent.setNodeProperties(Collections.singletonList(new EnvironmentVariablesNodeProperty( new Entry("JAVA_HOME", "/usr/lib/jvm/java-8-openjdk-amd64/jre")))); getJenkins().jenkins.addNode(agent); getJenkins().waitOnline(agent); return agent; } catch (Throwable e) { throw new AssumptionViolatedException("Failed to create docker container", e); } }
Example #2
Source File: DockerSSHConnector.java From yet-another-docker-plugin with MIT License | 6 votes |
@CheckForNull public StandardUsernameCredentials getCredentials() { String credentialsIdf; if (isNull(credentialsId)) { credentialsIdf = (isNull(credentials)) ? null : credentials.getId(); } else { credentialsIdf = credentialsId; } try { StandardUsernameCredentials credentialss; if (credentialsIdf == null) { credentialss = null; } else { credentialss = SSHLauncher.lookupSystemCredentials(credentialsIdf); } if (nonNull(credentialss)) { credentials = credentialss; } } catch (Throwable t) { // ignore } return credentials; }
Example #3
Source File: DockerComputerSSHLauncher.java From yet-another-docker-plugin with MIT License | 6 votes |
private SSHLauncher getSSHLauncher(String cloudId, DockerSlaveTemplate template, InspectContainerResponse inspect) { Preconditions.checkNotNull(template); Preconditions.checkNotNull(inspect); try { final HostAndPort hostAndPort = getHostAndPort(cloudId, inspect); LOG.info("Creating slave SSH launcher for '{}:{}'. Cloud: '{}'. Template: '{}'", hostAndPort.getHostText(), hostAndPort.getPort(), cloudId, template.getDockerContainerLifecycle().getImage()); return new SSHLauncher(hostAndPort.getHostText(), hostAndPort.getPort(), sshConnector.getCredentialsId(), sshConnector.getJvmOptions(), sshConnector.getJavaPath(), sshConnector.getPrefixStartSlaveCmd(), sshConnector.getSuffixStartSlaveCmd(), sshConnector.getLaunchTimeoutSeconds(), sshConnector.getMaxNumRetries(), sshConnector.getRetryWaitTime(), sshConnector.getSshHostKeyVerificationStrategy()); } catch (NullPointerException ex) { throw new RuntimeException("Error happened. Probably there is no mapped port 22 in host for SSL. Config=" + inspect, ex); } }
Example #4
Source File: WithMavenStepTest.java From pipeline-maven-plugin with MIT License | 5 votes |
@Before public void setup() throws Exception { super.setup(); JavaGitContainer slaveContainer = slaveRule.get(); DumbSlave agent = new DumbSlave("remote", "", "/home/test/slave", "1", Node.Mode.NORMAL, "", new SSHLauncher(slaveContainer.ipBound(22), slaveContainer.port(22), "test", "test", "", ""), RetentionStrategy.INSTANCE, Collections.<NodeProperty<?>>emptyList()); jenkinsRule.jenkins.addNode(agent); }
Example #5
Source File: DockerCreateContainer.java From yet-another-docker-plugin with MIT License | 5 votes |
public static ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new ListBoxModel(); } return new SSHUserListBoxModel().withMatching( SSHAuthenticator.matcher(Connection.class), CredentialsProvider.lookupCredentials( StandardUsernameCredentials.class, context, ACL.SYSTEM, SSHLauncher.SSH_SCHEME) ); }
Example #6
Source File: DockerComputerSSHConnector.java From docker-plugin with MIT License | 5 votes |
@Override public ComputerLauncher getSSHLauncher(InetSocketAddress address, DockerComputerSSHConnector connector) throws IOException { return new SSHLauncher(address.getHostString(), address.getPort(), getCredentialsId(), connector.getJvmOptions(), connector.getJavaPath(), connector.getPrefixStartSlaveCmd(), connector.getSuffixStartSlaveCmd(), connector.getLaunchTimeoutSeconds(), connector.getMaxNumRetries(), connector.getRetryWaitTime(), sshHostKeyVerificationStrategy ); }
Example #7
Source File: DockerSSHConnector.java From yet-another-docker-plugin with MIT License | 4 votes |
@Override public SSHLauncher launch(String host, TaskListener listener) throws IOException, InterruptedException { return new SSHLauncher(host, port, credentialsId, jvmOptions, javaPath, prefixStartSlaveCmd, suffixStartSlaveCmd, launchTimeoutSeconds, maxNumRetries, retryWaitTime, sshHostKeyVerificationStrategy); }
Example #8
Source File: DockerShellStepIT.java From yet-another-docker-plugin with MIT License | 4 votes |
@Test public void testDockerShellStep() throws Throwable { jRule.getInstance().setNumExecutors(0); // jRule.createSlave(); // jRule.createSlave("my-slave", "remote-slave", new EnvVars()); final UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, null, "description", "vagrant", "vagrant"); CredentialsStore store = CredentialsProvider.lookupStores(jRule.getInstance()).iterator().next(); store.addCredentials(Domain.global(), credentials); final SSHLauncher sshLauncher = new SSHLauncher("192.168.33.10", 22, credentials.getId(), "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", //jvmopts "", // String javaPath, "", // String prefixStartSlaveCmd, "", // String suffixStartSlaveCmd, 20, // Integer launchTimeoutSeconds, 1, // Integer maxNumRetries, 3,// Integer retryWaitTime new NonVerifyingKeyVerificationStrategy() ); final DumbSlave dumbSlave = new DumbSlave("docker-daemon", "/home/vagrant/jenkins2", sshLauncher); jRule.getInstance().addNode(dumbSlave); await().timeout(60, SECONDS).until(() -> assertThat(dumbSlave.getChannel(), notNullValue())); // String dockerfilePath = dumbSlave.getChannel().call(new DockerBuildImageStepTest.StringThrowableCallable()); final CredentialsYADockerConnector dockerConnector = new CredentialsYADockerConnector() .withConnectorType(JERSEY) .withServerUrl("tcp://127.0.0.1:2376") .withSslConfig(new LocalDirectorySSLConfig("/home/vagrant/keys")); // .withCredentials(new DockerDaemonFileCredentials(null, "docker-cert", "", // "/home/vagrant/keys")); DockerShellStep dockerShellStep = new DockerShellStep(); dockerShellStep.setShellScript("env && pwd"); dockerShellStep.setConnector(dockerConnector); FreeStyleProject project = jRule.createFreeStyleProject("test"); project.getBuildersList().add(dockerShellStep); project.save(); QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0); FreeStyleBuild freeStyleBuild = taskFuture.get(); jRule.waitForCompletion(freeStyleBuild); jRule.assertBuildStatusSuccess(freeStyleBuild); }
Example #9
Source File: DockerImageComboStepTest.java From yet-another-docker-plugin with MIT License | 4 votes |
@Ignore @Test public void testComboBuild() throws Throwable { jRule.getInstance().setNumExecutors(0); // jRule.createSlave(); // jRule.createSlave("my-slave", "remote-slave", new EnvVars()); final UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, null, "description", "vagrant", "vagrant"); CredentialsStore store = CredentialsProvider.lookupStores(jRule.getInstance()).iterator().next(); store.addCredentials(Domain.global(), credentials); final SSHLauncher sshLauncher = new SSHLauncher("192.168.33.10", 22, credentials.getId(), "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", //jvmopts "", // String javaPath, "", // String prefixStartSlaveCmd, "", // String suffixStartSlaveCmd, 20, // Integer launchTimeoutSeconds, 1, // Integer maxNumRetries, 3,// Integer retryWaitTime new NonVerifyingKeyVerificationStrategy() ); final DumbSlave dumbSlave = new DumbSlave("docker-daemon", "/home/vagrant/jenkins2", sshLauncher); jRule.getInstance().addNode(dumbSlave); await().timeout(60, SECONDS).until(() -> assertThat(dumbSlave.getChannel(), notNullValue())); String dockerfilePath = dumbSlave.getChannel().call(new StringThrowableCallable()); final CredentialsYADockerConnector dockerConnector = new CredentialsYADockerConnector() .withConnectorType(JERSEY) .withServerUrl("tcp://127.0.0.1:2376") .withSslConfig(new LocalDirectorySSLConfig("/home/vagrant/keys")); // .withCredentials(new DockerDaemonFileCredentials(null, "docker-cert", "", // "/home/vagrant/keys")); DockerBuildImage buildImage = new DockerBuildImage(); buildImage.setBaseDirectory(dockerfilePath); buildImage.setPull(true); buildImage.setTags(Collections.singletonList("localhost:5000/myfirstimage")); DockerImageComboStep comboStep = new DockerImageComboStep(dockerConnector, buildImage); comboStep.setClean(true); comboStep.setCleanupDangling(true); comboStep.setPush(true); FreeStyleProject project = jRule.createFreeStyleProject("test"); project.getBuildersList().add(comboStep); project.save(); QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0); FreeStyleBuild freeStyleBuild = taskFuture.get(); jRule.waitForCompletion(freeStyleBuild); jRule.assertBuildStatusSuccess(freeStyleBuild); }
Example #10
Source File: DockerBuildImageStepTest.java From yet-another-docker-plugin with MIT License | 4 votes |
@Test public void testBuild() throws Throwable { jRule.getInstance().setNumExecutors(0); // jRule.createSlave(); // jRule.createSlave("my-slave", "remote-slave", new EnvVars()); final UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, null, "description", "vagrant", "vagrant"); CredentialsStore store = CredentialsProvider.lookupStores(jRule.getInstance()).iterator().next(); store.addCredentials(Domain.global(), credentials); final SSHLauncher sshLauncher = new SSHLauncher("192.168.33.10", 22, credentials.getId(), "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", //jvmopts "", // String javaPath, "", // String prefixStartSlaveCmd, "", // String suffixStartSlaveCmd, 20, // Integer launchTimeoutSeconds, 1, // Integer maxNumRetries, 3,// Integer retryWaitTime new NonVerifyingKeyVerificationStrategy() ); final DumbSlave dumbSlave = new DumbSlave("docker-daemon", "/home/vagrant/jenkins2", sshLauncher); jRule.getInstance().addNode(dumbSlave); await().timeout(60, SECONDS).until(() -> assertThat(dumbSlave.getChannel(), notNullValue())); String dockerfilePath = dumbSlave.getChannel().call(new StringThrowableCallable()); final CredentialsYADockerConnector dockerConnector = new CredentialsYADockerConnector() .withConnectorType(JERSEY) .withServerUrl("tcp://127.0.0.1:2376") .withSslConfig(new LocalDirectorySSLConfig("/home/vagrant/keys")) ; // .withCredentials(new DockerDaemonFileCredentials(null, "docker-cert", "", // "/home/vagrant/keys")); DockerBuildImage buildImage = new DockerBuildImage(); buildImage.setBaseDirectory(dockerfilePath); buildImage.setPull(true); buildImage.setNoCache(true); DockerBuildImageStep dockerBuildImageStep = new DockerBuildImageStep(dockerConnector, buildImage); FreeStyleProject project = jRule.createFreeStyleProject("test"); project.getBuildersList().add(dockerBuildImageStep); project.save(); QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0); FreeStyleBuild freeStyleBuild = taskFuture.get(); jRule.waitForCompletion(freeStyleBuild); jRule.assertBuildStatusSuccess(freeStyleBuild); }
Example #11
Source File: DockerComputerSSHConnector.java From docker-plugin with MIT License | 4 votes |
@Override public String getUser() { return SSHLauncher.lookupSystemCredentials(credentialsId).getUsername(); }