Skip to content

Commit

Permalink
JENKINS-37627 Added outputfile to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
janario committed Mar 25, 2017
1 parent d9e4392 commit 434ce55
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
Expand Up @@ -41,6 +41,7 @@
import jenkins.security.MasterToSlaveCallable;

import jenkins.plugins.http_request.HttpRequest.DescriptorImpl;
import jenkins.plugins.http_request.HttpRequestStep.Execution;
import jenkins.plugins.http_request.auth.Authenticator;
import jenkins.plugins.http_request.util.HttpClientUtil;
import jenkins.plugins.http_request.util.HttpRequestNameValuePair;
Expand Down Expand Up @@ -93,16 +94,17 @@ static HttpRequestExecution from(HttpRequest http,
}
}

static HttpRequestExecution from(HttpRequestStep step, TaskListener taskListener) {
static HttpRequestExecution from(HttpRequestStep step, TaskListener taskListener, Execution execution) {
List<HttpRequestNameValuePair> headers = step.resolveHeaders();
FilePath outputFile = execution.resolveOutputFile();

return new HttpRequestExecution(
step.getUrl(), step.getHttpMode(), step.isIgnoreSslErrors(),
step.getRequestBody(), headers, step.getTimeout(),
step.getAuthentication(),

step.getValidResponseCodes(), step.getValidResponseContent(),
step.getConsoleLogResponseBody(), null,
step.getConsoleLogResponseBody(), outputFile,

taskListener.getLogger());
}
Expand Down
38 changes: 34 additions & 4 deletions src/main/java/jenkins/plugins/http_request/HttpRequestStep.java
@@ -1,5 +1,6 @@
package jenkins.plugins.http_request;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -16,6 +17,7 @@
import org.kohsuke.stapler.QueryParameter;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.TaskListener;
import hudson.util.FormValidation;
Expand All @@ -40,6 +42,7 @@ public final class HttpRequestStep extends AbstractStepImpl {
private String authentication = DescriptorImpl.authentication;
private String requestBody = DescriptorImpl.requestBody;
private List<HttpRequestNameValuePair> customHeaders = DescriptorImpl.customHeaders;
private String outputFile = DescriptorImpl.outputFile;

@DataBoundConstructor
public HttpRequestStep(String url) {
Expand Down Expand Up @@ -149,7 +152,16 @@ public List<HttpRequestNameValuePair> getCustomHeaders() {
return customHeaders;
}

@Override
public String getOutputFile() {
return outputFile;
}

@DataBoundSetter
public void setOutputFile(String outputFile) {
this.outputFile = outputFile;
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}
Expand All @@ -173,7 +185,7 @@ List<HttpRequestNameValuePair> resolveHeaders() {
return headers;
}

@Extension
@Extension
public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
public static final boolean ignoreSslErrors = HttpRequest.DescriptorImpl.ignoreSslErrors;
public static final HttpMode httpMode = HttpRequest.DescriptorImpl.httpMode;
Expand All @@ -186,6 +198,7 @@ public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
public static final String authentication = HttpRequest.DescriptorImpl.authentication;
public static final String requestBody = HttpRequest.DescriptorImpl.requestBody;
public static final List <HttpRequestNameValuePair> customHeaders = Collections.<HttpRequestNameValuePair>emptyList();
public static final String outputFile = "";

public DescriptorImpl() {
super(Execution.class);
Expand Down Expand Up @@ -237,7 +250,7 @@ public static final class Execution extends AbstractSynchronousNonBlockingStepEx

@Override
protected ResponseContentSupplier run() throws Exception {
HttpRequestExecution exec = HttpRequestExecution.from(step, listener);
HttpRequestExecution exec = HttpRequestExecution.from(step, listener, this);

Launcher launcher = getContext().get(Launcher.class);
if (launcher != null) {
Expand All @@ -249,5 +262,22 @@ protected ResponseContentSupplier run() throws Exception {

private static final long serialVersionUID = 1L;

}
FilePath resolveOutputFile() {
String outputFile = step.getOutputFile();
if (outputFile == null || outputFile.trim().isEmpty()) {
return null;
}

try {
FilePath workspace = getContext().get(FilePath.class);
if (workspace == null) {
throw new IllegalStateException("Could not find workspace to save file outputFile: " + outputFile +
". You should use it inside a 'node' block");
}
return workspace.child(outputFile);
} catch (IOException | InterruptedException e) {
throw new IllegalStateException(e);
}
}
}
}
Expand Up @@ -23,6 +23,9 @@
<f:entry field="timeout" title="Connection timeout" help="/plugin/http_request/help-timeout.html">
<f:number default="${descriptor.timeout}"/>
</f:entry>
<f:entry field="outputFile" title="Output response to file" help="/plugin/http_request/help-outputFile.html">
<f:textbox />
</f:entry>
<f:entry field="consoleLogResponseBody" title="Response body in console?" help="/plugin/http_request/help-consoleLogResponseBody.html">
<f:booleanRadio />
</f:entry>
Expand Down

0 comments on commit 434ce55

Please sign in to comment.