feat(publisher): add Freestyle Publisher post-build HTTP Request action - #338
feat(publisher): add Freestyle Publisher post-build HTTP Request action#338Ralnoc wants to merge 1 commit into
Conversation
- Duplicated help-*.html files from HttpRequestStep for all configurable fields in HttpRequestPublisher: url, httpMode, ignoreSslErrors, authentication, acceptType, wrapAsMultipart, and a general help.html overview - Duplicated config.jelly from HttpRequestStep for HttpRequestPublisher to implement a full inline form mirroring HttpRequest's UI, making publisher configuration self-contained - Updated HttpMode with getPublisherFillItems() to populate only outbound CRUD operations in the publisher dropdown - Updated test suite to construct HttpRequestPublisher directly to mirror testing implemented for HttpRequestStep - Updated Groovy scripts to include an embedded HTTP echo server for testing additional HTTP modes. - Enhanced Maven profile scripts to seed demo jobs for new HTTP methods as build steps and post-build actions. - Migrated canned GET and POST payloads to reusable Groovy templates for improved maintainability. - Added a `configure-test-jobs` Maven profile to handle seeding of build-step and post-build action demo jobs using `gmavenplus-plugin` with Groovy scripts. - Updated and migrated `test-response.json` to `src/test/resources/testdata/test-get-response.json` for consistency. - Added new payload `test-post-response.json` for validating POST-call workflows. - Automatically launches Jenkins and opens a browser when using the Maven configuration.
|
@MarkEWaite - Here is the PR for the change I was speaking to you about, when I reached out for Adopting the plugin. My hope is to get this approved, then I'll start working through the Issues and PR Backlog. |
Thanks. I've requested a GitHub Copilot review so that it can provide feedback first. |
| return (HttpRequestPublisher) super.newInstance(req, formData); | ||
| } | ||
|
|
||
| public ListBoxModel doFillHttpModeItems() { |
| return (HttpRequestPublisher) super.newInstance(req, formData); | ||
| } | ||
|
|
||
| public ListBoxModel doFillHttpModeItems() { |
| return HttpMode.getPublisherFillItems(); | ||
| } | ||
|
|
||
| public ListBoxModel doFillAcceptTypeItems() { |
| return HttpMode.getPublisherFillItems(); | ||
| } | ||
|
|
||
| public ListBoxModel doFillAcceptTypeItems() { |
| return MimeType.getContentTypeFillItems(); | ||
| } | ||
|
|
||
| public ListBoxModel doFillContentTypeItems() { |
| return MimeType.getContentTypeFillItems(); | ||
| } | ||
|
|
||
| public ListBoxModel doFillResponseHandleItems() { |
| return items; | ||
| } | ||
|
|
||
| public ListBoxModel doFillAuthenticationItems(@AncestorInPath Item project, |
| return HttpRequest.DescriptorImpl.fillAuthenticationItems(project, url); | ||
| } | ||
|
|
||
| public ListBoxModel doFillProxyAuthenticationItems(@AncestorInPath Item project, |
| return HttpRequest.DescriptorImpl.fillAuthenticationItems(project, url); | ||
| } | ||
|
|
||
| public FormValidation doCheckValidResponseCodes(@QueryParameter String value) { |
| return HttpRequest.DescriptorImpl.fillAuthenticationItems(project, url); | ||
| } | ||
|
|
||
| public FormValidation doCheckValidResponseCodes(@QueryParameter String value) { |
There was a problem hiding this comment.
Pull request overview
This PR adds a new Freestyle-compatible post-build action (HttpRequestPublisher) that reuses the existing HTTP request execution logic to perform outbound HTTP calls after an AbstractBuild completes, addressing the lack of a Publisher mentioned in #337.
Changes:
- Introduces
HttpRequestPublisher(aRecorder) with a Jenkins UI (config.jelly) and help content for Freestyle/post-build usage. - Adds an outbound-only HTTP-mode allowlist for the publisher via
HttpMode.SUPPORTED_HTTP_MODES+ a publisher-specific fill-items method. - Adds extensive publisher-focused test coverage and a Maven profile to seed demo jobs / run a local echo harness for
hpi:run.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/jenkins/plugins/http_request/HttpRequestPublisher.java | Adds the new Freestyle post-build Publisher implementation and its descriptor dropdown population. |
| src/main/java/jenkins/plugins/http_request/HttpRequestExecution.java | Adds a factory method to build an execution from the new publisher. |
| src/main/java/jenkins/plugins/http_request/HttpMode.java | Adds a publisher-specific outbound allowlist and dropdown population helper. |
| src/main/java/jenkins/plugins/http_request/HttpPostMode.java | Introduces a POST/PUT/DELETE/PATCH enum intended for allowlisting (currently redundant). |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/config.jelly | Adds the Jenkins configuration UI for the new Publisher. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help.html | Adds help content for the new Publisher (currently pipeline-oriented / inaccurate). |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-acceptType.html | Adds field help for Accept header configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-authentication.html | Adds field help for authentication selection. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-consoleLogResponseBody.html | Adds field help for console logging behavior. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-contentType.html | Adds field help for Content-Type header configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-httpMode.html | Adds field help for HTTP mode selection. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-httpProxy.html | Adds field help for proxy configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-ignoreSslErrors.html | Adds field help for SSL ignore behavior. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-multipartName.html | Adds field help for multipart upload name configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-outputFile.html | Adds field help for writing response output to a file. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-quiet.html | Adds field help for quiet logging mode. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-requestBody.html | Adds field help for request body configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-responseHandle.html | Adds field help for response handling mode. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-timeout.html | Adds field help for request timeout configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-uploadFile.html | Adds field help for upload-file configuration (contains invalid HTML). |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-url.html | Adds field help for URL configuration. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-useSystemProperties.html | Adds field help for using system properties (currently not correctly linked from UI). |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-validResponseCodes.html | Adds field help for valid response codes (contains a spelling typo). |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-validResponseContent.html | Adds field help for validating response content. |
| src/main/resources/jenkins/plugins/http_request/HttpRequestPublisher/help-wrapAsMultipart.html | Adds field help for multipart wrapping behavior. |
| src/test/java/jenkins/plugins/http_request/HttpRequestPublisherTestBase.java | Adds a shared base class to reuse the existing echo harness for publisher tests. |
| src/test/java/jenkins/plugins/http_request/HttpRequestFreestylePublisherTest.java | Adds end-to-end Freestyle publisher coverage (modes, request body, headers, response validation, dropdown allowlist). |
| src/test/java/jenkins/plugins/http_request/HttpRequestPublisherRoundTripTest.java | Adds save/reload round-trip coverage and documents mode coercion behavior. |
| src/test/java/jenkins/plugins/http_request/HttpRequestPublisherTest.java | Adds a broad mirrored test suite using the existing harness patterns. |
| src/test/java/jenkins/plugins/http_request/HttpRequestPublisherStepCredentialsTest.java | Adds mirrored credentials tracking/retrieval tests for the publisher context. |
| src/test/resources/testdata/test-get-response.json | Adds canned GET response JSON for harness/demo usage. |
| src/test/resources/testdata/test-post-response.json | Adds canned POST response JSON for harness/demo usage. |
| pom.xml | Adds a configure-test-jobs profile (echo harness + demo job seeding) and introduces gmavenplus plugin wiring. |
| .idea/codeStyles/Project.xml | Updates IDE code style settings (not directly related to publisher feature). |
Files not reviewed (1)
- .idea/codeStyles/Project.xml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VirtualChannel channel = launcher.getChannel(); | ||
| if (channel == null) { | ||
| throw new IllegalStateException("Launcher doesn't support remoting but it is required"); | ||
| } | ||
| channel.call(exec); | ||
|
|
||
| return true; |
| public ListBoxModel doFillProxyAuthenticationItems(@AncestorInPath Item project, | ||
| @QueryParameter String url) { | ||
| return HttpRequest.DescriptorImpl.fillAuthenticationItems(project, url); | ||
| } |
| /** | ||
| * A standalone post-build action that performs an HTTP request. It shares its request semantics | ||
| * with {@link HttpRequest} and {@link HttpRequestStep}, but only permits the HTTP methods listed | ||
| * in {@link HttpPostMode}. | ||
| */ |
| public enum HttpPostMode { | ||
| POST, | ||
| PUT, | ||
| DELETE, | ||
| PATCH; |
| <div> | ||
| <p> | ||
| Performs an HTTP request, and returns a response object. | ||
| <p>Usage example:</p> | ||
| <pre> | ||
| def response = httpRequest 'http://localhost:8080/jenkins/api/json?pretty=true' | ||
| println("Status: "+response.status) | ||
| println("Content: "+response.content) | ||
| </pre> | ||
| <p>If Jenkins restarts after the HTTP request is made, but before the HTTP response is received, the HTTP request fails.</p> | ||
| <p><tt>validResponseCodes</tt> is a comma-separated string of single values or <tt>from:to</tt> ranges. For example <tt>'200'</tt> to accept only <tt>200</tt> or <tt>'201,301:303'</tt> to accept <tt>201</tt> as well as the range from <tt>301</tt> to <tt>303</tt>.</p> | ||
| </p> | ||
| <p> | ||
| The methods of the response object are: | ||
| <ul> | ||
| <li> | ||
| <tt>String getContent()</tt>: The HTTP Response entity. This means the text of the response without the headers. If the response does not contain an entity, <tt>getContent()</tt> returns null. | ||
| </li> | ||
| <li> | ||
| <tt>int getStatus()</tt>: The HTTP status code. | ||
| </li> | ||
| </ul> | ||
| </p> | ||
| </div> |
| <f:entry field="authentication" title="Authenticate" help="/plugin/http_request/help-authentication.html"> | ||
| <f:select /> | ||
| </f:entry> | ||
| <f:entry field="useSystemProperties" title="Use system properties" help="/plugin/http_request/use-system-properties.html"> |
| @@ -0,0 +1,8 @@ | |||
| <div> | |||
| Configure response code to mark an execution as <b>success</b>.<br/> | |||
| You can configure simple code such as "200" or multiple codes separeted by <b>comma(',')</b> e.g. "200,404,500"<br/> | |||
| <div> | ||
| Path to the upload file, relative to build workspace or absolute path.</p> | ||
| Can be used to upload a file as <i>multipart/form-data</i> <b>POST</b> request. | ||
| The according content type should be set above, defaults to <i>application/octet-stream</i> otherwise. | ||
| </div> |
| <dependency> | ||
| <groupId>org.codehaus.gmavenplus</groupId> | ||
| <artifactId>gmavenplus-plugin</artifactId> | ||
| <version>5.0.0</version> | ||
| <scope>test</scope> | ||
| </dependency> |
| def response = JsonOutput.toJson([ | ||
| "status": "ok", | ||
| "message": jsonEscape(method + " call against the Jenkins Test Harness succeeded."), | ||
| "method": method, | ||
| "path": jsonEscape(path), | ||
| "timestamp": new Date().toInstant().toString(), | ||
| "receivedContentType": jsonStringOrNull(contentType), | ||
| "receivedPayloadLength": length, | ||
| "payload": JsonOutput.toJson(rawBody), | ||
| ]) |
@MarkEWaite - I see that I have a few things to look through. 😅 I'll start working through them all. An observation, though. Some of these are triggering on code that is a duplication from the existing Thoughts? |
I wouldn't refactor in this pull request. I think that it is OK to dismiss comments from GitHub Copilot, especially if you're willing to create an issue that reminds you of the future need.
I agree. Smaller improvement steps have been better for me than larger improvement steps. |
Adds
HttpRequestPublisher, a standalone post-build action ("Post-build Actions" /Recorder) that lets Freestyle (and otherAbstractBuild-based) jobs perform an outbound HTTP request as a final step — e.g. notifying a downstream system, closing out a deployment ticket, or hitting a webhook once the build itself is done. Also includes a new Maven profile calledconfigure-test-jobswhich builds out test jobs for use withinhpi:runthat also includes a payload response process for post actions.Resolves #337.
Testing done
HttpRequestFreestylePublisherTest— exercises the publisher end-to-end throughFreeStyleProject#getPublishersList(): supported modes succeed, the default (GET) mode still executes since there's no runtime rejection, request body / custom headers / response-content validation all behave the same as the build step, and the descriptor'shttpModedropdown offers only the outbound modes.HttpRequestPublisherRoundTripTest— confirms the publisher's configuration survives a save/reload round trip, and documents that a mode outside the dropdown (e.g. GET) gets coerced to the first offered option on save rather than rejected.HttpRequestPublisherTest/HttpRequestPublisherStepCredentialsTest— mirror the existingHttpRequest/HttpRequestStepcoverage (content types, auth, redirects, credential tracking, certificate/basic-auth pipelines) against the shared test harness.configure-test-jobsMaven profile: seeded demo jobs (includinghttp-request-publisher-demo) run against the local echo harness and produce the expected responses.Submitter checklist