org.jenkinsci.plugins.workflow.steps.StepContext Java Examples
The following examples show how to use
org.jenkinsci.plugins.workflow.steps.StepContext.
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: BackwardCompatibility.java From lockable-resources-plugin with MIT License | 6 votes |
@Initializer(after = InitMilestone.JOB_LOADED) public static void compatibilityMigration() { LOG.log(Level.FINE, "lockable-resource-plugin compatibility migration task run"); List<LockableResource> resources = LockableResourcesManager.get().getResources(); for (LockableResource resource : resources) { List<StepContext> queuedContexts = resource.getQueuedContexts(); if (!queuedContexts.isEmpty()) { for (StepContext queuedContext : queuedContexts) { List<String> resourcesNames = new ArrayList<>(); resourcesNames.add(resource.getName()); LockableResourcesStruct resourceHolder = new LockableResourcesStruct(resourcesNames, "", 0); LockableResourcesManager.get().queueContext(queuedContext, Arrays.asList(resourceHolder), resource.getName(), null); } queuedContexts.clear(); } } }
Example #2
Source File: WithMavenStepExecution2.java From pipeline-maven-plugin with MIT License | 6 votes |
@Override protected void finished(StepContext context) throws Exception { mavenSpyLogProcessor.processMavenSpyLogs(context, tempBinDir, options, mavenPublisherStrategy); try { tempBinDir.deleteRecursive(); } catch (IOException | InterruptedException e) { BuildListener listener = context.get(BuildListener.class); try { if (e instanceof IOException) { Util.displayIOException((IOException) e, listener); // Better IOException display on windows } e.printStackTrace(listener.fatalError("Error deleting temporary files")); } catch (Throwable t) { t.printStackTrace(); } } }
Example #3
Source File: Office365ConnectorSendStepTest.java From office-365-connector-plugin with Apache License 2.0 | 6 votes |
@Test public void start_CreatesExecution() { // given String message = "Hi there."; Office365ConnectorSendStep step = new Office365ConnectorSendStep(null); step.setMessage(message); StepContext stepContext = mock(StepContext.class); // when StepExecution execution = step.start(stepContext); // then assertThat(execution.getContext()).isEqualTo(stepContext); StepParameters stepParameters = Deencapsulation.getField(execution, "stepParameters"); assertThat(stepParameters.getMessage()).isEqualTo(message); }
Example #4
Source File: InvokerRunsPublisher.java From pipeline-maven-plugin with MIT License | 5 votes |
private void executeReporter(StepContext context, TaskListener listener, List<Element> testEvents) throws IOException, InterruptedException { FilePath workspace = context.get(FilePath.class); final String fileSeparatorOnAgent = XmlUtils.getFileSeparatorOnRemote(workspace); Run run = context.get(Run.class); Launcher launcher = context.get(Launcher.class); for (Element testEvent : testEvents) { Element projectElt = XmlUtils.getUniqueChildElement(testEvent, "project"); Element pluginElt = XmlUtils.getUniqueChildElement(testEvent, "plugin"); Element reportsDirectoryElt = XmlUtils.getUniqueChildElementOrNull(pluginElt, "reportsDirectory"); Element cloneProjectsToElt = XmlUtils.getUniqueChildElementOrNull(pluginElt, "cloneProjectsTo"); Element projectsDirectoryElt = XmlUtils.getUniqueChildElementOrNull(pluginElt, "projectsDirectory"); MavenArtifact mavenArtifact = XmlUtils.newMavenArtifact(projectElt); MavenSpyLogProcessor.PluginInvocation pluginInvocation = XmlUtils.newPluginInvocation(pluginElt); String reportsDirectory = expandAndRelativize(reportsDirectoryElt, "reportsDirectory", testEvent, projectElt, workspace,listener); String projectsDirectory = expandAndRelativize(projectsDirectoryElt, "projectsDirectory", testEvent, projectElt, workspace,listener); String cloneProjectsTo = expandAndRelativize(cloneProjectsToElt, "cloneProjectsTo", testEvent, projectElt, workspace,listener); if (reportsDirectory == null || projectsDirectory == null ) continue; String testResults = reportsDirectory + fileSeparatorOnAgent + "*.xml"; listener.getLogger().println("[withMaven] invokerPublisher - Archive invoker results for Maven artifact " + mavenArtifact.toString() + " generated by " + pluginInvocation + ": " + testResults); MavenInvokerRecorder archiver = new MavenInvokerRecorder("**/" + reportsDirectory + "/BUILD*.xml", "**/" + (cloneProjectsTo != null ? cloneProjectsTo : projectsDirectory)); try { archiver.perform(run, workspace, launcher, listener); } catch (Exception e) { listener.error("[withMaven] invokerPublisher - Silently ignore exception archiving Invoker runs for Maven artifact " + mavenArtifact.toString() + " generated by " + pluginInvocation + ": " + e); LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(testEvent), e); } } }
Example #5
Source File: ContainerExecDecoratorTest.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Before public void configureCloud() throws Exception { cloud = setupCloud(this, name); client = cloud.connect(); deletePods(client, getLabels(this, name), false); String image = "busybox"; Container c = new ContainerBuilder().withName(image).withImagePullPolicy("IfNotPresent").withImage(image) .withCommand("cat").withTty(true).build(); Container d = new ContainerBuilder().withName(image + "1").withImagePullPolicy("IfNotPresent").withImage(image) .withCommand("cat").withTty(true).withWorkingDir("/home/jenkins/agent1").build(); String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789"); pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName) .withLabels(getLabels(this, name)).endMetadata().withNewSpec().withContainers(c, d).withNodeSelector(Collections.singletonMap("kubernetes.io/os", "linux")).withTerminationGracePeriodSeconds(0L).endSpec().build()); System.out.println("Created pod: " + pod.getMetadata().getName()); PodTemplate template = new PodTemplate(); template.setName(pod.getMetadata().getName()); agent = mock(KubernetesSlave.class); when(agent.getNamespace()).thenReturn(client.getNamespace()); when(agent.getPodName()).thenReturn(pod.getMetadata().getName()); doReturn(cloud).when(agent).getKubernetesCloud(); when(agent.getPod()).thenReturn(Optional.of(pod)); StepContext context = mock(StepContext.class); when(context.get(Node.class)).thenReturn(agent); decorator = new ContainerExecDecorator(); decorator.setNodeContext(new KubernetesNodeContext(context)); decorator.setContainerName(image); }
Example #6
Source File: WithMavenStepExecution2.java From pipeline-maven-plugin with MIT License | 5 votes |
WithMavenStepExecution2(StepContext context, WithMavenStep step) throws Exception { super(context); this.step = step; // Or just delete these fields and inline: listener = context.get(TaskListener.class); ws = context.get(FilePath.class); launcher = context.get(Launcher.class); env = context.get(EnvVars.class); build = context.get(Run.class); }
Example #7
Source File: AddGitLabMergeRequestCommentStep.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private TaskListener getTaskListener() { StepContext context = getContext(); if (!context.isReady()) { return null; } try { return context.get(TaskListener.class); } catch (Exception x) { return null; } }
Example #8
Source File: GitLabCommitStatusStep.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private TaskListener getTaskListener(StepContext context) { try { if (!context.isReady()) { return null; } return context.get(TaskListener.class); } catch (Exception x) { return null; } }
Example #9
Source File: AbstractEndpointStepExecution.java From docker-workflow-plugin with MIT License | 5 votes |
@Override protected void finished(StepContext context) throws Exception { try { material.close(); } catch (IOException x) { Logger.getLogger(AbstractEndpointStepExecution.class.getName()).log(Level.WARNING, null, x); } }
Example #10
Source File: EC2ShareAmiStepTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Before public void setupSdk() throws Exception { PowerMockito.mockStatic(AWSClientFactory.class); this.ec2 = Mockito.mock(AmazonEC2.class); PowerMockito.when(AWSClientFactory.create(Mockito.any(AwsSyncClientBuilder.class), Mockito.any(StepContext.class))) .thenReturn(this.ec2); }
Example #11
Source File: WithPodStepExecution.java From kubernetes-pipeline-plugin with Apache License 2.0 | 5 votes |
@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; }
Example #12
Source File: WithPodStepExecution.java From kubernetes-pipeline-plugin with Apache License 2.0 | 5 votes |
@Override public void onSuccess(StepContext context, Object result) { try (KubernetesFacade kubernetes = new KubernetesFacade()){ kubernetes.deletePod(podName); } catch (IOException e) { LOGGER.warning("Failed to properly cleanup"); } finally { context.onSuccess(result); } }
Example #13
Source File: DockerNodeStepExecution.java From docker-plugin with MIT License | 5 votes |
public DockerNodeStepExecution(StepContext context, @Nullable DockerComputerConnector connector, String dockerHost, String credentialsId, String image, String remoteFs) { super(context); if( connector!=null ) { assertIsSerializableDockerComputerConnector(connector); this.connector = (Serializable) connector; } else { assertIsSerializableDockerComputerConnector(DEFAULT_CONNECTOR); this.connector = (Serializable) DEFAULT_CONNECTOR; } this.dockerHost = dockerHost; this.credentialsId = credentialsId; this.image = image; this.remoteFs = remoteFs; }
Example #14
Source File: LambdaVersionCleanupStepTest.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Before public void setupSdk() throws Exception { PowerMockito.mockStatic(AWSClientFactory.class); this.awsLambda = Mockito.mock(AWSLambda.class); this.cloudformation = Mockito.mock(AmazonCloudFormation.class); PowerMockito.when(AWSClientFactory.create(Mockito.any(AwsSyncClientBuilder.class), Mockito.any(StepContext.class))) .thenAnswer( (x) -> { if (x.getArgumentAt(0, AwsSyncClientBuilder.class) instanceof AWSLambdaClientBuilder) { return awsLambda; } else { return cloudformation; } }); }
Example #15
Source File: HubotAbstractSynchronousNonBlockingStepExecution.java From hubot-steps-plugin with Apache License 2.0 | 5 votes |
protected HubotAbstractSynchronousNonBlockingStepExecution(StepContext context) throws IOException, InterruptedException { super(context); run = context.get(Run.class); listener = context.get(TaskListener.class); envVars = context.get(EnvVars.class); }
Example #16
Source File: WaitDeployStep.java From pipeline-aws-plugin with Apache License 2.0 | 4 votes |
@Override public StepExecution start(StepContext context) throws Exception { return new WaitDeployStep.Execution(this.deploymentId, context); }
Example #17
Source File: DownloadAttachmentStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
protected Execution(final DownloadAttachmentStep step, final StepContext context) throws IOException, InterruptedException { super(context); this.step = step; }
Example #18
Source File: DeleteIssueLinkStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
@Override public StepExecution start(StepContext context) throws Exception { return new Execution(this, context); }
Example #19
Source File: DeleteIssueRemoteLinksStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
@Override public StepExecution start(StepContext context) throws Exception { return new Execution(this, context); }
Example #20
Source File: UploadAttachmentStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
protected Execution(final UploadAttachmentStep step, final StepContext context) throws IOException, InterruptedException { super(context); this.step = step; }
Example #21
Source File: EditCommentStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
@Override public StepExecution start(StepContext context) throws Exception { return new Execution(this, context); }
Example #22
Source File: UploadAttachmentStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
@Override public StepExecution start(StepContext context) throws Exception { return new Execution(this, context); }
Example #23
Source File: JqlSearchStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
protected Execution(final JqlSearchStep step, final StepContext context) throws IOException, InterruptedException { super(context); this.step = step; }
Example #24
Source File: CFNDeleteStackSetStep.java From pipeline-aws-plugin with Apache License 2.0 | 4 votes |
public Execution(CFNDeleteStackSetStep step, @Nonnull StepContext context) { super(context); this.step = step; }
Example #25
Source File: JiraStepExecution.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
protected JiraStepExecution(final StepContext context) throws IOException, InterruptedException { super(context); run = context.get(Run.class); listener = context.get(TaskListener.class); envVars = context.get(EnvVars.class); }
Example #26
Source File: EditCommentStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
protected Execution(final EditCommentStep step, final StepContext context) throws IOException, InterruptedException { super(context); this.step = step; }
Example #27
Source File: GeneralNonBlockingStepExecution.java From pipeline-maven-plugin with MIT License | 4 votes |
protected GeneralNonBlockingStepExecution(StepContext context) { super(context); }
Example #28
Source File: EditIssueStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
protected Execution(final EditIssueStep step, final StepContext context) throws IOException, InterruptedException { super(context); this.step = step; }
Example #29
Source File: TeeStep.java From pipeline-utility-steps-plugin with MIT License | 4 votes |
@Override protected void finished(StepContext sc) throws Exception { filter.close(); }
Example #30
Source File: EditIssueStep.java From jira-steps-plugin with Apache License 2.0 | 4 votes |
@Override public StepExecution start(StepContext context) throws Exception { return new Execution(this, context); }