Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX-JENKINS-41421] Extend StepImpl to pass along submitterParameter #820

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions blueocean-pipeline-api-impl/pom.xml
Expand Up @@ -73,6 +73,12 @@
<artifactId>credentials</artifactId>
</dependency>

<!-- Needed for input step submitterParameter -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-input-step</artifactId>
</dependency>

<!-- Not needed by blueocean runtime but adds to blueocean experience -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -28,8 +28,12 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.export.Exported;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

import static io.jenkins.blueocean.rest.model.KnownCapabilities.JENKINS_WORKFLOW_RUN;

Expand All @@ -40,6 +44,7 @@
*/
@Capability(JENKINS_WORKFLOW_RUN)
public class PipelineRunImpl extends AbstractRunImpl<WorkflowRun> {
private static final Logger logger = LoggerFactory.getLogger(PipelineRunImpl.class);
public PipelineRunImpl(WorkflowRun run, Link parent) {
super(run, parent);
}
Expand All @@ -62,8 +67,12 @@ public Container<BlueChangeSetEntry> getChangeSet() {
@Override
public BlueRunState getStateObj() {
InputAction inputAction = run.getAction(InputAction.class);
if(inputAction != null && inputAction.getExecutions().size() > 0){
return BlueRunState.PAUSED;
try {
if(inputAction != null && inputAction.getExecutions().size() > 0){
return BlueRunState.PAUSED;
}
} catch (InterruptedException | TimeoutException e) {
logger.error("Error getting StateObject from execution context: "+e.getMessage(), e);
}
return super.getStateObj();
}
Expand Down
Expand Up @@ -43,6 +43,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
* @author Vivek Pandey
Expand Down Expand Up @@ -178,13 +179,13 @@ public HttpResponse submitInputStep(StaplerRequest request) {
" have an InputAction.");
}

InputStepExecution execution = inputAction.getExecution(id);
if (execution == null) {
throw new ServiceException.BadRequestExpception(
String.format("Error processing Input Submit request. This Run instance does not" +
" have an Input with an id of '%s'.", id));
}
try {
InputStepExecution execution = inputAction.getExecution(id);
if (execution == null) {
throw new ServiceException.BadRequestExpception(
String.format("Error processing Input Submit request. This Run instance does not" +
" have an Input with an id of '%s'.", id));
}
//if abort, abort and return
if(body.get(ABORT_ELEMENT) != null && body.getBoolean(ABORT_ELEMENT)){
return execution.doAbort();
Expand All @@ -200,7 +201,7 @@ public HttpResponse submitInputStep(StaplerRequest request) {
listener.onStepContinue(execution.getInput(), run);
}
return response;
} catch (IOException | InterruptedException | ServletException e) {
} catch (IOException | InterruptedException | TimeoutException e) {
throw new ServiceException.UnexpectedErrorException("Error processing Input Submit request."+e.getMessage());
}
}
Expand All @@ -219,6 +220,7 @@ private void preSubmissionCheck(InputStepExecution execution){
private Object parseValue(InputStepExecution execution, JSONArray parameters, StaplerRequest request) throws IOException, InterruptedException {
Map<String, Object> mapResult = new HashMap<String, Object>();

InputStep input = execution.getInput();
for(Object o: parameters){
JSONObject p = (JSONObject) o;
String name = (String) p.get(NAME_ELEMENT);
Expand All @@ -228,7 +230,7 @@ private Object parseValue(InputStepExecution execution, JSONArray parameters, St
}

ParameterDefinition d=null;
for (ParameterDefinition def : execution.getInput().getParameters()) {
for (ParameterDefinition def : input.getParameters()) {
if (def.getName().equals(name))
d = def;
}
Expand All @@ -241,6 +243,12 @@ private Object parseValue(InputStepExecution execution, JSONArray parameters, St
}
mapResult.put(name, convert(name, v));
}
// If a destination value is specified, push the submitter to it.
String valueName = input.getSubmitterParameter();
if (valueName != null && !valueName.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use StringUtils.isNotBlank(valueName)?

Copy link
Collaborator Author

@scherler scherler Feb 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, possibly InputStepImpl.parseValue() should be refactored to avoid working off form submission and work just off JSONArray and also expose this and some other method public. I noted that time in PR/comment but missed to follow it up with JIRA/PR in pipeline-onput-step plugin. I will follow it up.

Authentication a = Jenkins.getAuthentication();
mapResult.put(valueName, a.getName());
}
switch (mapResult.size()) {
case 0:
return null; // no value if there's no parameter
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

/**
* Gives steps inside
Expand Down Expand Up @@ -182,16 +183,16 @@ public void atomNode(@CheckForNull FlowNode before, @Nonnull FlowNode atomNode,
InputStep inputStep=null;
if(PipelineNodeUtil.isPausedForInputStep((StepAtomNode) atomNode, inputAction)){
status = new NodeRunStatus(BlueRun.BlueRunResult.UNKNOWN, BlueRun.BlueRunState.PAUSED);
for(InputStepExecution execution: inputAction.getExecutions()){
try {
FlowNode node = execution.getContext().get(FlowNode.class);
if(node != null && node.equals(atomNode)){
inputStep = execution.getInput();
break;
}
} catch (IOException | InterruptedException e) {
logger.error("Error getting FlowNode from execution context: "+e.getMessage(), e);
try {
for(InputStepExecution execution: inputAction.getExecutions()){
FlowNode node = execution.getContext().get(FlowNode.class);
if(node != null && node.equals(atomNode)){
inputStep = execution.getInput();
break;
}
}
} catch (IOException | InterruptedException | TimeoutException e) {
logger.error("Error getting FlowNode from execution context: "+e.getMessage(), e);
}
}else{
status = new NodeRunStatus(atomNode);
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -297,6 +297,11 @@
<artifactId>pipeline-stage-step</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-input-step</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-organization-folder</artifactId>
Expand Down