/** @see CpsFlowExecution#getScript */ /* accessible to Jelly */ public String getOriginalScript() { CpsFlowExecution execution = getExecutionBlocking(); return execution != null ? execution.getScript() : "???"; }
@Override public CpsFlowExecution create(FlowDefinition def, FlowExecutionOwner owner, List<? extends Action> actions) throws IOException { Run original = Run.fromExternalizableId(originRunId); String origScript = null; boolean origSandbox = true; if (original instanceof FlowExecutionOwner.Executable) { FlowExecutionOwner originalOwner = ((FlowExecutionOwner.Executable) original).asFlowExecutionOwner(); if (originalOwner != null) { try { for (FlowCopier copier : ExtensionList.lookup(FlowCopier.class)) { copier.copy(originalOwner, owner); } } catch (InterruptedException x) { throw new IOException("Failed to copy metadata", x); } FlowExecution origExecution = originalOwner.getOrNull(); if (origExecution instanceof CpsFlowExecution) { origScript = ((CpsFlowExecution) origExecution).getScript(); origSandbox = ((CpsFlowExecution) origExecution).isSandbox(); } } } if (origScript != null) { return new CpsFlowExecution(origScript, origSandbox, owner); } else { return null; } }
/** Verifies all the universal post-build cleanup was done, regardless of pass/fail state. */ static void verifyCompletedCleanly(Jenkins j, WorkflowRun run) throws Exception { // Assert that we have the appropriate flow graph entries FlowExecution exec = run.getExecution(); List<FlowNode> heads = exec.getCurrentHeads(); Assert.assertEquals(1, heads.size()); verifyNoTasksRunning(j); Assert.assertEquals(0, exec.getCurrentExecutions(false).get().size()); if (exec instanceof CpsFlowExecution) { CpsFlowExecution cpsFlow = (CpsFlowExecution)exec; assert cpsFlow.getStorage() != null; Assert.assertFalse("Should always be able to retrieve script", StringUtils.isEmpty(cpsFlow.getScript())); Assert.assertNull("We should have no Groovy shell left or that's a memory leak", cpsFlow.getShell()); Assert.assertNull("We should have no Groovy shell left or that's a memory leak", cpsFlow.getTrustedShell()); Assert.assertTrue(cpsFlow.done); assert cpsFlow.isComplete(); assert cpsFlow.heads.size() == 1; Map.Entry<Integer, FlowHead> finalHead = cpsFlow.heads.entrySet().iterator().next(); assert finalHead.getValue().get() instanceof FlowEndNode; Assert.assertEquals(cpsFlow.storage.getNode(finalHead.getValue().get().getId()), finalHead.getValue().get()); } verifyExecutionRemoved(run); }