Search in sources :

Example 1 with StepDescriptor

use of org.jenkinsci.plugins.workflow.steps.StepDescriptor in project blueocean-plugin by jenkinsci.

the class PipelineEventListener method newMessage.

private Message newMessage(PipelineEventChannel.Event event, FlowNode flowNode, Collection<String> branch) {
    Message message = newMessage(event, flowNode.getExecution());
    message.set(PipelineEventChannel.EventProps.pipeline_step_flownode_id, flowNode.getId());
    message.set(PipelineEventChannel.EventProps.pipeline_context, toPath(branch));
    if (currentStageName != null) {
        message.set(PipelineEventChannel.EventProps.pipeline_step_stage_name, currentStageName.get(flowNode.getExecution()));
        message.set(PipelineEventChannel.EventProps.pipeline_step_stage_id, currentStageId.get(flowNode.getExecution()));
    }
    if (flowNode instanceof StepNode) {
        StepNode stepNode = (StepNode) flowNode;
        StepDescriptor stepDescriptor = stepNode.getDescriptor();
        if (stepDescriptor != null) {
            message.set(PipelineEventChannel.EventProps.pipeline_step_name, stepDescriptor.getFunctionName());
            // TODO: Better event choice, more granularity - like only firing when this results in a status change
            if (stepDescriptor instanceof ExecutorStep.DescriptorImpl) {
                Run<?, ?> run = runFor(flowNode.getExecution());
                if (run != null) {
                    publishJobEvent(run, Events.JobChannel.job_run_started);
                }
                if (flowNode.getPersistentAction(QueueItemAction.class) != null) {
                    // Needed because this is expected everywhere apparently.
                    message.set(PipelineEventChannel.EventProps.pipeline_step_is_paused, String.valueOf(false));
                }
            }
        }
    }
    if (flowNode instanceof StepAtomNode) {
        Run<?, ?> run = runFor(flowNode.getExecution());
        if (run != null) {
            boolean pausedForInputStep = PipelineNodeUtil.isPausedForInputStep((StepAtomNode) flowNode, run.getAction(InputAction.class));
            if (pausedForInputStep) {
                // Fire job event to tell we are paused
                // We will publish on the job channel
                publishJobEvent(run, Events.JobChannel.job_run_paused);
            }
            message.set(PipelineEventChannel.EventProps.pipeline_step_is_paused, String.valueOf(pausedForInputStep));
        }
    }
    return message;
}
Also used : StepNode(org.jenkinsci.plugins.workflow.graph.StepNode) SimpleMessage(org.jenkinsci.plugins.pubsub.SimpleMessage) RunMessage(org.jenkinsci.plugins.pubsub.RunMessage) Message(org.jenkinsci.plugins.pubsub.Message) QueueItemAction(org.jenkinsci.plugins.workflow.actions.QueueItemAction) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)

Example 2 with StepDescriptor

use of org.jenkinsci.plugins.workflow.steps.StepDescriptor in project blueocean-plugin by jenkinsci.

the class PipelineStepImpl method getStepType.

@Override
public String getStepType() {
    FlowNode flowNode = this.node.getNode();
    if (flowNode instanceof StepNode && !(flowNode instanceof StepEndNode)) {
        StepNode stepNode = (StepNode) flowNode;
        StepDescriptor descriptor = stepNode.getDescriptor();
        if (descriptor != null)
            return descriptor.getId();
    }
    return "unknown";
}
Also used : StepNode(org.jenkinsci.plugins.workflow.graph.StepNode) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 3 with StepDescriptor

use of org.jenkinsci.plugins.workflow.steps.StepDescriptor in project blueocean-plugin by jenkinsci.

the class PipelineMetadataService method doPipelineStepMetadata.

/**
 * Function to return all step descriptors present in the system when accessed through the REST API
 */
@GET
@TreeResponse
public ExportedPipelineFunction[] doPipelineStepMetadata() {
    List<ExportedPipelineFunction> pd = new ArrayList<>();
    for (StepDescriptor d : StepDescriptor.all()) {
        if (includeStep(d)) {
            ExportedPipelineStep step = getStepMetadata(d);
            if (step != null) {
                pd.add(step);
            }
        }
    }
    List<Descriptor<?>> metaStepDescriptors = new ArrayList<Descriptor<?>>();
    populateMetaSteps(metaStepDescriptors, Builder.class);
    populateMetaSteps(metaStepDescriptors, Publisher.class);
    for (Descriptor<?> d : metaStepDescriptors) {
        ExportedPipelineFunction metaStep = getStepMetadata(d);
        if (metaStep != null) {
            pd.add(metaStep);
        }
    }
    return pd.toArray(new ExportedPipelineFunction[pd.size()]);
}
Also used : ArrayList(java.util.ArrayList) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) DeclarativeAgentDescriptor(org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor) ToolDescriptor(hudson.tools.ToolDescriptor) Descriptor(hudson.model.Descriptor) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) GET(org.kohsuke.stapler.verb.GET)

Aggregations

StepDescriptor (org.jenkinsci.plugins.workflow.steps.StepDescriptor)3 StepNode (org.jenkinsci.plugins.workflow.graph.StepNode)2 Descriptor (hudson.model.Descriptor)1 ToolDescriptor (hudson.tools.ToolDescriptor)1 TreeResponse (io.jenkins.blueocean.commons.stapler.TreeResponse)1 ArrayList (java.util.ArrayList)1 DeclarativeAgentDescriptor (org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor)1 Message (org.jenkinsci.plugins.pubsub.Message)1 RunMessage (org.jenkinsci.plugins.pubsub.RunMessage)1 SimpleMessage (org.jenkinsci.plugins.pubsub.SimpleMessage)1 QueueItemAction (org.jenkinsci.plugins.workflow.actions.QueueItemAction)1 StepAtomNode (org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)1 StepEndNode (org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)1 GET (org.kohsuke.stapler.verb.GET)1