Refine search
public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws Exception { synchronized (jenkins) { DumbSlave slave = new DumbSlave(nodeName, "dummy", createTmpDir().getPath(), "1", Node.Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env), RetentionStrategy.NOOP, Collections.EMPTY_LIST); jenkins.addNode(slave); return slave; } }
public DumbSlave createSlave(boolean waitForChannelConnect) throws Exception { DumbSlave slave = createSlave(); if (waitForChannelConnect) { long start = System.currentTimeMillis(); while (slave.getChannel() == null) { if (System.currentTimeMillis() > (start + 10000)) { throw new IllegalStateException("Timed out waiting on DumbSlave channel to connect."); } Thread.sleep(200); } } return slave; }
public DumbSlave createSlave(JenkinsRule j) throws Exception { DumbSlave s = j.createSlave(); s.getComputer().connect(false).get(); // wait for the slave to fully get connected return s; }
public void disconnectSlave(DumbSlave slave) throws Exception { slave.getComputer().disconnect(new OfflineCause.ChannelTermination(new Exception("terminate"))); long start = System.currentTimeMillis(); while (slave.getChannel() != null) { if (System.currentTimeMillis() > (start + 10000)) { throw new IllegalStateException("Timed out waiting on DumbSlave channel to disconnect."); } Thread.sleep(200); } }
public Node call() throws Exception { // simulate the delay in provisioning a new slave, // since it's normally some async operation. Thread.sleep(time); System.out.println("launching slave"); final DumbSlave slave = rule.createSlave(label); for (NodeProperty nodeProperty : nodeProperties) { slave.getNodeProperties().add(updateWithNode(nodeProperty, slave)); } computer = slave.toComputer(); computer.connect(false).get(); synchronized (DummyCloudImpl.this) { System.out.println(computer.getName()+" launch"+(computer.isOnline()?"ed successfully":" failed")); System.out.println(computer.getLog()); } return slave; } }
@Test public void getContainerLogWithRestart() throws Exception { story.then(r -> { configureCloud(); r.jenkins.addNode(new DumbSlave("slave", "dummy", tmp.newFolder("remoteFS").getPath(), "1", Node.Mode.NORMAL, "", new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList())); // TODO JENKINS-26398 clumsy WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition(loadPipelineScript("getContainerLogWithRestart.groovy") , true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); // we need to wait until we are sure that the sh // step has started... r.waitForMessage("+ sleep 5", b); }); story.then(r -> { WorkflowRun b = r.jenkins.getItemByFullName("p", WorkflowJob.class).getBuildByNumber(1); r.assertBuildStatusSuccess(r.waitForCompletion(b)); r.assertLogContains("INFO: Handshaking", b); r.assertLogContains("INFO: Connected", b); }); } }
@Issue("JENKINS-16533") @Test public void pollingRespectExternalsWithRevision() throws Exception { // trunk has svn:externals="-r 1 ^/vendor vendor" (pinned) // latest commit on vendor is r3 (> r1) File repo = new CopyExisting(getClass().getResource("JENKINS-16533.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + repo.toURI().toURL().getPath() + "trunk"); // pinned externals should be recorded with ::p in revisions.txt FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); // should not find any change (pinned externals should be skipped on poll) // fail if it checks the revision of external URL larger than the pinned revision assertFalse(p.poll(StreamTaskListener.fromStdout()).hasChanges()); }
@Issue("JENKINS-53709") @Test public void popContextVarsOnBodyCompletion() { rr.then(r -> { DumbSlave s = r.createOnlineSlave(); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition("node('" + s.getNodeName() + "') {\n" + " parallel one: {\n" + " echo '" + s.getNodeName() + "'\n" + " }\n" + "}\n" + "semaphore 'wait'\n", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); SemaphoreStep.waitForStart("wait/1", b); r.jenkins.removeNode(s); }); rr.then(r -> { WorkflowRun b = r.jenkins.getItemByFullName("demo", WorkflowJob.class).getBuildByNumber(1); SemaphoreStep.waitForStart("wait/1", b); SemaphoreStep.success("wait/1", null); while (b.isBuilding()) { // Before the fix for JENKINS-53709, the job hangs forever while attempting to rehydrate the agent. r.assertLogNotContains("Jenkins doesn’t have label", b); Thread.sleep(100); } r.assertBuildStatusSuccess(b); }); }
private void doRepeatedArchiving(boolean slave) throws Exception { if (slave) { DumbSlave s = j.createOnlineSlave(); project.setAssignedLabel(s.getSelfLabel()); } project.getPublishersList().removeAll(JUnitResultArchiver.class); project.getBuildersList().add(new SimpleArchive("A", 7, 0)); project.getBuildersList().add(new SimpleArchive("B", 0, 1)); FreeStyleBuild build = j.assertBuildStatus(Result.UNSTABLE, project.scheduleBuild2(0).get()); List<TestResultAction> actions = build.getActions(TestResultAction.class); assertEquals(1, actions.size()); TestResultAction testResultAction = actions.get(0); TestResult result = testResultAction.getResult(); assertNotNull("no TestResult", result); assertEquals("should have 1 failing test", 1, testResultAction.getFailCount()); assertEquals("should have 1 failing test", 1, result.getFailCount()); assertEquals("should have 8 total tests", 8, testResultAction.getTotalCount()); assertEquals("should have 8 total tests", 8, result.getTotalCount()); assertEquals(/* ⅞ = 87.5% */87, testResultAction.getBuildHealth().getScore()); } public static final class SimpleArchive extends Builder {
public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws Exception { synchronized (jenkins) { DumbSlave slave = new DumbSlave(nodeName, "dummy", createTmpDir().getPath(), "1", Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList()); jenkins.addNode(slave); return slave; } }
@LocalData @Test public void testSlave() throws Exception { DumbSlave s = rule.createOnlineSlave(); project.setAssignedLabel(s.getSelfLabel()); FilePath src = new FilePath(rule.jenkins.getRootPath(), "jobs/" + BASIC_TEST_PROJECT + "/workspace/"); assertNotNull(src); FilePath dest = s.getWorkspaceFor(project); assertNotNull(dest); src.copyRecursiveTo("*.xml", dest); testBasic(); }
@BeforeClass public static void setUpAgentAndCreds() throws Exception { s = j.createOnlineSlave(); s.setLabelString("some-label docker here"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"), new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first"))); s.setNumExecutors(2); s2 = j.createOnlineSlave(); s2.setLabelString("other-docker"); s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"), new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second"))); CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next(); String usernamePasswordCredentialsId = "FOOcredentials"; UsernamePasswordCredentialsImpl usernamePassword = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, usernamePasswordCredentialsId, "sample", usernamePasswordUsername, usernamePasswordPassword); store.addCredentials(Domain.global(), usernamePassword); }
@Override public void evaluate() throws Throwable { logger.record(CpsFlowExecution.class, Level.WARNING).capture(100); DumbSlave s = story.j.createOnlineSlave(); s.setLabelString("remote quick"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true")));
@Test @Issue("JENKINS-50339") public void shouldSerializeException() throws Exception { DumbSlave agent = j.createOnlineSlave(); try { agent.getChannel().call(new ErrorCallable()); } catch (SVNException e) { return; // fine } }
@Override public void evaluate() throws Throwable { jenkins().setNumExecutors(0); DumbSlave s = createSlave(story.j); String nodeName = s.getNodeName(); p = jenkins().createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition( "def s = jenkins.model.Jenkins.instance.getComputer('" + nodeName + "')\n" + "def r = s.node.rootPath\n" + "def p = r.getRemote()\n" + "semaphore 'wait'\n" + // make sure these values are still alive "assert s.nodeName=='" + nodeName + "'\n" + "assert r.getRemote()==p : r.getRemote() + ' vs ' + p;\n" + "assert r.channel==s.channel : r.channel.toString() + ' vs ' + s.channel\n", false)); startBuilding(); SemaphoreStep.waitForStart("wait/1", b); assertTrue(b.isBuilding()); } });
@Test public void runInPodWithRestart() throws Exception { story.then(r -> { configureCloud(); r.jenkins.addNode(new DumbSlave("slave", "dummy", tmp.newFolder("remoteFS").getPath(), "1", Node.Mode.NORMAL, "", new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList())); // TODO JENKINS-26398 clumsy WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runInPodWithRestartWithLongSleep.groovy") , true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); // we need to wait until we are sure that the sh // step has started... r.waitForMessage("+ sleep 5", b); }); story.then(r -> { WorkflowRun b = r.jenkins.getItemByFullName("p", WorkflowJob.class).getBuildByNumber(1); r.assertLogContains("finished the test!", r.assertBuildStatusSuccess(r.waitForCompletion(b))); }); }
private void invokeTestPollingExternalsForFile() throws Exception { // trunk has svn:externals="^/vendor/target.txt target.txt" File repo = new CopyExisting(getClass().getResource("JENKINS-20165.zip")).allocate(); String path = "file://" + repo.toURI().toURL().getPath(); SubversionSCM scm = new SubversionSCM(path + "trunk"); // first checkout FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); // update target.txt in vendor SubversionSCM vendor = new SubversionSCM(path + "vendor"); createWorkingCopy(vendor); changeFiles("target.txt"); commitWorkingCopy("update"); // should detect change assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges()); } }
public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws Exception { synchronized (hudson) { DumbSlave slave = new DumbSlave(nodeName, "dummy", createTmpDir().getPath(), "1", Node.Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env), RetentionStrategy.NOOP, Collections.EMPTY_LIST); hudson.addNode(slave); return slave; } }
@RandomlyFails("TimeoutException from basic") @LocalData("All") @Test public void slave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setAssignedLabel(s.getSelfLabel()); FilePath src = new FilePath(j.jenkins.getRootPath(), "jobs/junit/workspace/"); assertNotNull(src); FilePath dest = s.getWorkspaceFor(project); assertNotNull(dest); src.copyRecursiveTo("*.xml", dest); basic(); }
@Test public void runInPodWithRestartWithMultipleContainerCalls() throws Exception { story.then(r -> { configureCloud(); r.jenkins.addNode(new DumbSlave("slave", "dummy", tmp.newFolder("remoteFS").getPath(), "1", Node.Mode.NORMAL, "", new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList())); // TODO JENKINS-26398 clumsy WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runInPodWithRestartWithMultipleContainerCalls.groovy") , true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); // we need to wait until we are sure that the sh // step has started... r.waitForMessage("+ sleep 5", b); }); story.then(r -> { WorkflowRun b = r.jenkins.getItemByFullName("p", WorkflowJob.class).getBuildByNumber(1); r.assertLogContains("finished the test!", r.assertBuildStatusSuccess(r.waitForCompletion(b))); }); }