@Override protected FilePath tryResolve() { return FilePathUtils.find(slave, path); } @Override public String toString() {
/** * Same as {@link #getNodeNameOrNull} but throws a diagnostic exception in case of failure. * @param f a file, possible remote * @return a node name ({@code ""} for master), if known * @throws IllegalStateException if the association to a node is unknown */ public static @Nonnull String getNodeName(@Nonnull FilePath f) throws IllegalStateException { String name = getNodeNameOrNull(f); if (name != null) { return name; } else { throw new IllegalStateException("no known slave for " + f + " among " + Listener.getChannelNames()); } }
/** * Verifies that 'b' has completed successfully. */ public void assertBuildCompletedSuccessfully() throws Exception { assertBuildCompletedSuccessfully(b); }
@Override public boolean start() throws Exception { StepContext context = getContext(); value = "one"; context.newBodyInvoker(). withContexts(EnvironmentExpander.merge(context.get(EnvironmentExpander.class), new ExpanderImpl(this))). withCallback(BodyExecutionCallback.wrap(context)). start(); return false; } @Override public void onResume() {
@Override public void evaluate() throws Throwable { rebuildContext(story.j); SemaphoreStep.success("b/1", null); SemaphoreStep.waitForStart("c/1", b); SemaphoreStep.success("c/1", null); story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)); story.j.assertLogContains("abc", b); } });
SpecialEnvSlave(File remoteFS, ComputerLauncher launcher, String nodeName, @Nonnull String labels, Map<String,String> env) throws Descriptor.FormException, IOException { super(nodeName, remoteFS.getAbsolutePath(), launcher); setNumExecutors(1); setLabelString(labels); setMode(Mode.NORMAL); setRetentionStrategy(RetentionStrategy.NOOP); this.env = env; } @Override public Computer createComputer() {
@Override public void evaluate() throws Throwable { assertEquals(JenkinsRule.DummySecurityRealm.class, jenkins().getSecurityRealm().getClass()); rebuildContext(story.j); assertThatWorkflowIsSuspended(); story.j.waitForMessage("again running as someone", b); CheckAuth.finish(true); story.j.assertLogContains("finally running as someone", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b))); } });
/** @deprecated use {@link JenkinsRule#waitForCompletion} instead */ public void waitForWorkflowToComplete() throws Exception { do { waitForWorkflowToSuspend(e); } while (!e.isComplete()); }
private WorkspaceListLeasePickle(WorkspaceList.Lease lease) { slave = FilePathUtils.getNodeNameOrNull(lease.path); path = lease.path.getRemote(); }
private FilePathPickle(FilePath v) { slave = FilePathUtils.getNodeName(v); path = v.getRemote(); }
@Override public void preOnline(Computer c, Channel channel, FilePath root, TaskListener listener) throws IOException, InterruptedException { addChannel(channel, c.getName()); }
@Override public String getDisplayName() { return getFunctionName(); // TODO would be nice for this to be the default, perhaps? } }
/** * Asserts that {@link #e} is in the suspended state and has nothing more to execute. */ public void assertThatWorkflowIsSuspended() throws Exception { assertThatWorkflowIsSuspended(b, e); }
@Override public String getDisplayName() { return getFunctionName(); } }
@Override public StepExecution start(StepContext context) throws Exception { return new Execution(context); } private static class Execution extends StepExecution {
public void waitForWorkflowToSuspend() throws Exception { waitForWorkflowToSuspend(e); }
@Override public Computer createComputer() { return new SpecialEnvComputer(this, env); } }
/** * If a prohibited method is called, execution should fail. */ @Issue("JENKINS-26541") @Test public void sandboxRejection() throws Exception { assertRejected("Jenkins.getInstance()"); assertRejected("parallel(main: {Jenkins.getInstance()})"); assertRejected("parallel(main: {parallel(main2: {Jenkins.getInstance()})})"); assertRejected("node {parallel(main: {ws {parallel(main2: {ws {Jenkins.getInstance()}})}})}"); } private void assertRejected(String script) throws Exception {
@Override public void evaluate() throws Throwable { rebuildContext(story.j); story.j.assertBuildStatus(Result.FAILURE, b); } });
@Override public void onOnline(Computer c, TaskListener l) { // TODO currently preOnline is not called for MasterComputer if (c instanceof Jenkins.MasterComputer) { addChannel(c.getChannel(), c.getName()); } } @Override public void preOnline(Computer c, Channel channel, FilePath root, TaskListener listener) throws IOException, InterruptedException {