/** * Equivalent to calling {@link withContext} on each object. */ public BodyInvoker withContexts(Collection<?> overrides) { for (Object o : overrides) withContext(o); return this; }
/** * Equivalent to calling {@link withContext} on each object. */ public BodyInvoker withContexts(Collection<?> overrides) { for (Object o : overrides) withContext(o); return this; }
@Override public boolean start() throws Exception { Map<String, String> overridesM = new HashMap<>(); for (String pair : overrides) { int split = pair.indexOf('='); assert split != -1; overridesM.put(pair.substring(0, split), pair.substring(split + 1)); } getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), EnvironmentExpander.constant(overridesM))). withCallback(BodyExecutionCallback.wrap(getContext())). start(); return false; }
/** * {@inheritDoc} */ @Override public boolean start() throws Exception { StepContext context = getContext(); EnvironmentExpander currentEnvironment = context.get(EnvironmentExpander.class); EnvironmentExpander terminalEnvironment = EnvironmentExpander.constant(Collections.singletonMap("TERM", step.getColorMapName())); context.newBodyInvoker().withContext(createConsoleLogFilter(context)) .withContext(EnvironmentExpander.merge(currentEnvironment, terminalEnvironment)) .withCallback(BodyExecutionCallback.wrap(context)).start(); return false; }
@Override public boolean start() throws Exception { FilePath dir = getContext().get(FilePath.class).child(path); getContext().get(TaskListener.class).getLogger().println("Running in " + dir); getContext().newBodyInvoker() .withContext(dir) // Could use a dedicated BodyExecutionCallback here if we wished to print a message at the end ("Returning to ${cwd}"): .withCallback(BodyExecutionCallback.wrap(getContext())) .start(); return false; }
@Override public boolean start() throws Exception { StepContext context = getContext(); sockets = new ArrayList<String>(); initRemoteAgent(); context.newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new ExpanderImpl(this))). withCallback(new Callback(this)).withDisplayName(null).start(); return false; }
/** * {@inheritDoc} */ @Override public boolean start() throws Exception { StepContext context = getContext(); context.get(Run.class).replaceAction(new ColorizedAction(colorMapName)); EnvironmentExpander currentEnvironment = context.get(EnvironmentExpander.class); EnvironmentExpander terminalEnvironment = EnvironmentExpander.constant(Collections.singletonMap("TERM", colorMapName)); context.newBodyInvoker() .withContext(EnvironmentExpander.merge(currentEnvironment, terminalEnvironment)) .withCallback(BodyExecutionCallback.wrap(context)).start(); return false; }
@Override public final boolean start() throws Exception { KeyMaterialFactory keyMaterialFactory = newKeyMaterialFactory(); KeyMaterial material = keyMaterialFactory.materialize(); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new Expander(material))). withCallback(new Callback(material)). start(); return false; }
@Override public boolean onStart(SessionManager sessionManager) throws Exception { sessionManager.start(); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new NamespaceExpander(session.getNamespace()))). withCallback(new SessionManagerStopCallback(sessionManager)). start(); return false; }
@Override public boolean onStart(SessionManager sessionManager) throws Exception { sessionManager.start(); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new NamespaceExpander(session.getNamespace()))). withCallback(new SessionManagerStopCallback(sessionManager)). start(); return false; }
@Override public boolean start() throws Exception { StepContext context = getContext(); if (obj instanceof ConsoleLogFilter) { obj = BodyInvoker.mergeConsoleLogFilters(context.get(ConsoleLogFilter.class), (ConsoleLogFilter) obj); } else if (obj instanceof LauncherDecorator) { obj = BodyInvoker.mergeLauncherDecorators(context.get(LauncherDecorator.class), (LauncherDecorator) obj); } else if (obj instanceof EnvironmentExpander) { obj = EnvironmentExpander.merge(context.get(EnvironmentExpander.class), (EnvironmentExpander) obj); } context.newBodyInvoker().withContext(obj).withCallback(BodyExecutionCallback.wrap(context)).start(); return false; }
@Override public boolean start() throws Exception { StepContext context = getContext(); podName = step.getName() + "-" + UUID.randomUUID().toString(); final AtomicBoolean podAlive = new AtomicBoolean(false); final CountDownLatch podStarted = new CountDownLatch(1); final CountDownLatch podFinished = new CountDownLatch(1); //The body is executed async. so we can't use try with resource here. final KubernetesFacade kubernetes = new KubernetesFacade(); PodTemplate newTemplate = new PodTemplate(); newTemplate.setName(podName); newTemplate.setLabel(step.getName()); newTemplate.setVolumes(step.getVolumes()); newTemplate.setContainers(step.getContainers()); newTemplate.setNodeSelector(step.getNodeSelector()); newTemplate.setServiceAccount(step.getServiceAccount()); //Get host using env vars and fallback to computer name (integration point with kubernetes-plugin). String hostname = env.get(Constants.HOSTNAME, computer.getName()); String jobname = env.get(Constants.JOB_NAME, computer.getName()); kubernetes.createPod(hostname, jobname, newTemplate, workspace.getRemote(), step.getLabels()); kubernetes.watch(podName, podAlive, podStarted, podFinished, true); podStarted.await(); String containerName = step.getContainers().get(step.getContainers().size() - 1).getName(); context.newBodyInvoker() .withContext(BodyInvoker .mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new PodExecDecorator(kubernetes, podName, containerName, podAlive, podStarted, podFinished))) .withCallback(new PodCallback(podName)) .start(); return false; }
.withContext(workspace) .withCallback(BodyExecutionCallback.wrap(getContext())) .start();
@Override public boolean start() throws Exception { StepContext context = getContext(); BodyInvoker bodyInvoker = context.newBodyInvoker() .withCallback(new Callback()); if (step.isActivity()) { bodyInvoker = bodyInvoker.withContext( BodyInvoker.mergeConsoleLogFilters( context.get(ConsoleLogFilter.class), new ConsoleLogFilterImpl2(id, timeout) ) ); } body = bodyInvoker.start(); resetTimer(); return false; // execution is asynchronous }
@Override public boolean start() throws Exception { FilePath f = getContext().get(FilePath.class).child(file); getContext().newBodyInvoker(). withContext(BodyInvoker.mergeConsoleLogFilters(getContext().get(ConsoleLogFilter.class), new TeeFilter(f))). withCallback(BodyExecutionCallback.wrap(getContext())). start(); return false; }
private void doStart() throws Exception { SimpleBuildWrapper.Context c = new SimpleBuildWrapper.Context(); Run<?, ?> run = getContext().get(Run.class); delegate.setUp(c, run, getContext().get(FilePath.class), getContext().get(Launcher.class), getContext().get(TaskListener.class), getContext().get(EnvVars.class)); BodyInvoker bodyInvoker = getContext().newBodyInvoker(); Map<String,String> overrides = c.getEnv(); if (!overrides.isEmpty()) { bodyInvoker.withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new ExpanderImpl(overrides))); } ConsoleLogFilter filter = delegate.createLoggerDecorator(run); if (filter != null) { bodyInvoker.withContext(BodyInvoker.mergeConsoleLogFilters(getContext().get(ConsoleLogFilter.class), filter)); } SimpleBuildWrapper.Disposer disposer = c.getDisposer(); bodyInvoker.withCallback(disposer != null ? new Callback2(disposer) : BodyExecutionCallback.wrap(getContext())).start(); }
@Override public boolean start() throws Exception { final EnvVars awsEnv = new EnvVars(); this.withCredentials(this.getContext().get(Run.class), awsEnv); this.withProfile(awsEnv); this.withRegion(awsEnv); this.withEndpointUrl(awsEnv); this.withRole(awsEnv); this.withFederatedUserId(awsEnv); EnvironmentExpander expander = new EnvironmentExpander() { @Override public void expand(@Nonnull EnvVars envVars) { envVars.overrideAll(awsEnv); } }; this.getContext().newBodyInvoker() .withContext(EnvironmentExpander.merge(this.getContext().get(EnvironmentExpander.class), expander)) .withCallback(BodyExecutionCallback.wrap(this.getContext())) .start(); return false; }
decorator.setShell(shell); getContext().newBodyInvoker() .withContext(BodyInvoker .mergeLauncherDecorators(getContext().get(LauncherDecorator.class), decorator)) .withCallback(new ContainerExecCallback(decorator))
@Override public boolean start() throws Exception { TaskListener listener = getContext().get(TaskListener.class); NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); sessionId = generateSessionId(); namespace = generateNamespaceId(step.getName(), step.getPrefix(), sessionId); client = getKubernetesClient(); isOpenshift = client.isAdaptable(OpenShiftClient.class); configuration = new DefaultConfigurationBuilder() .withNamespace(namespace) .withNamespaceLazyCreateEnabled(step.isNamespaceLazyCreateEnabled()) .withNamespaceDestroyEnabled(step.isNamespaceDestroyEnabled()) .withMasterUrl(client.getMasterUrl()) .build(); StreamLogger logger = new StreamLogger(listener.getLogger()); LabelProvider labelProvider = new MapLabelProvider(step.getLabels()); namespaceService = isOpenshift ? new OpenshiftNamespaceService.ImmutableOpenshiftNamespaceService(client, configuration, labelProvider, logger) : new DefaultNamespaceService.ImmutableNamespaceService(client, configuration, labelProvider, logger); if (!namespaceService.exists(namespace) && configuration.isNamespaceLazyCreateEnabled()) { namespaceService.create(namespace); } namespaceAction.push(namespace); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new NamespaceExpander(namespace))). withCallback(new NamespaceDestructionCallback(namespace, configuration, namespaceService, namespaceAction)). start(); return false; }
@Override public boolean start() throws Exception { TaskListener listener = getContext().get(TaskListener.class); NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); sessionId = generateSessionId(); namespace = generateNamespaceId(step.getName(), step.getPrefix(), sessionId); client = getKubernetesClient(); isOpenshift = client.isAdaptable(OpenShiftClient.class); configuration = new DefaultConfigurationBuilder() .withNamespace(namespace) .withNamespaceLazyCreateEnabled(step.isNamespaceLazyCreateEnabled()) .withNamespaceDestroyEnabled(step.isNamespaceDestroyEnabled()) .withMasterUrl(client.getMasterUrl()) .build(); StreamLogger logger = new StreamLogger(listener.getLogger()); LabelProvider labelProvider = new MapLabelProvider(step.getLabels()); namespaceService = isOpenshift ? new OpenshiftNamespaceService.ImmutableOpenshiftNamespaceService(client, configuration, labelProvider, logger) : new DefaultNamespaceService.ImmutableNamespaceService(client, configuration, labelProvider, logger); if (!namespaceService.exists(namespace) && configuration.isNamespaceLazyCreateEnabled()) { namespaceService.create(namespace); } namespaceAction.push(namespace); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new NamespaceExpander(namespace))). withCallback(new NamespaceDestructionCallback(namespace, configuration, namespaceService, namespaceAction)). start(); return false; }