• Stars
    star
    154
  • Rank 233,534 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 11 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This plugin does a request to an url with some parameters.

Http Request Plugin

Build Contributors Jenkins Plugin Installs Plugin GitHub release

Overview
This plugin sends a HTTP/HTTPS request to a user specified URL. The request is made via job execution in Jenkins and depending on the HTTP response the job can be marked as failed (configurable). For example, responses such as 404 and 500 can make the job fail. When a job fails it will log the response to help identify the problem.

According to the setting of HTTP mode the request will be performed either using HTTP GET or POST. If there is no such setting then it will use the default from global settings. Default there is POST.

Features

The following powerful features are available in both Pipeline and traditional project types, giving you greater control and flexibility over your builds:

  • Programmable HTTP method: Choose from a variety of HTTP methods, including GET, POST, PUT, PATCH, DELETE, or HEAD, to suit your project’s specific needs.

  • Programmable range of expected response codes: Specify a range of expected response codes for your build, and if the response code falls outside the specified range, the build will fail, saving you time and hassle.

  • Supports Basic Authentication: Use Basic Authentication to ensure that only authorized users can access your project’s resources, providing an additional layer of security.

  • Supports Form Authentication: Form Authentication enables users to authenticate themselves by submitting a username and password through a form, ensuring that only authorized users can access your resources.

  • Specify a required string in the response: Ensure that a specific string is present in the response by specifying it beforehand. If the string is not present, the build will fail, alerting you to the issue.

  • Set a connection timeout limit: Prevent builds from taking too long by setting a connection timeout limit. If the limit is exceeded, the build will fail, saving you time and resources.

  • Set an "Accept" header directly: Set the "Accept" header directly, providing greater control over the type of data that the server returns in response to a request.

  • Set a "Content-Type" header directly: Set the "Content-Type" header directly, specifying the type of data that you are sending in your request, helping to ensure that the server can correctly process your request.

  • Set any custom header: Set any custom header that you require, enabling you to interact with APIs or web services that require specific headers or authentication protocols.

Basic plugin features

ℹ️
Feature Availability

The following features are only present in the non-pipeline version of the plugin. For the Pipeline version, these features are available programmatically.

  • You can send the build parameters as URL query strings

  • You can store the response to a file, built-in to the plugin

Pipeline features

In a Pipeline job, you have total control over how the url is formed. Suppose you have a build parameter called “param1”, you can pass it to the HTTP request programmatically like so:

httpRequest "http://httpbin.org/response-headers?param1=${param1}"

If you wish to save the response to a file, you need to grab a workspace. You can do this with a node Pipeline step. For example:

def response = httpRequest "http://httpbin.org/response-headers?param1=${param1}"
node() {
    writeFile file: 'response.txt', text: response.content
}

You can access the response status code, content and headers programmatically:

def response = httpRequest "http://httpbin.org/response-headers?param1=${param1}"
println("Status: ${response.status}")
println("Response: ${response.content}")
println("Headers: ${response.headers}")

You may also send content in the body of the request, such as for a PATCH request:

// create payload
def patchOrg = """
    {"description": "$description"}
"""
def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON',
                           httpMode: 'PATCH', requestBody: patchOrg,
                           url: "https://api.github.com/orgs/${orgName}"

You may also send content in the body of the request, such as for a POST request:

httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON',
            httpMode: 'POST', quiet: true,
            requestBody: '''{
               "display-name" : "my_Username",
               "email" : "[email protected]",
               "password" : {
                  "value" : "my_password"
               },
            }''',
            url: 'https://api.github.com/orgs/${orgName}'

You can also set custom headers:

def response = httpRequest customHeaders: [[name: 'foo', value: 'bar']]

You can also set custom headers with mask set true:

def response =  httpRequest customHeaders: [[maskValue: true, name: 'foo', value: 'bar']],
                            url: 'https://api.github.com/orgs/${orgName}'

You can send multipart/form-data forms:

def response = httpRequest httpMode: 'POST', formData: [
               [contentType: 'application/json', name: 'model', body: '{"foo": "bar"}'],
               [contentType: 'text/plain', name: 'file', fileName: 'readme.txt',
               uploadFile: 'data/lipsum.txt']]

You can send a request with form-data:

def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_FORM_DATA',
                           formData: [[body: '''{
                                         "name" : "example",
                                         "type" : "bot"
                                        }''',
                           contentType: 'text/plain', fileName: 'sample', name: 'data',
                           uploadFile: './files/readme.txt']],
                           httpMode: 'POST', quiet: true, responseHandle: 'NONE', timeout: null,
                           url: 'https://api.github.com/orgs/${orgName}',
                           validResponseCodes: '200,404', validResponseContent: 'token'

You can send multipart file and multipart entity name:

def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_OCTETSTREAM',
                           httpMode: 'POST', multipartName: 'file', quiet: true,
                           responseHandle: 'NONE', timeout: null, uploadFile: './files/readme.txt',
                           url: 'https://api.github.com/orgs/${orgName}'

You can send a request with SSL error ignored

def response = httpRequest ignoreSslErrors: true, responseHandle: 'NONE',
                           url: 'https://api.github.com/orgs/${orgName}'

You can send a request with http proxy

def response = httpRequest httpProxy: 'http://proxy.local', responseHandle: 'NONE',
                           url: 'https://api.github.com/orgs/${orgName}'

You can send a request with http proxy authenticate

def response = httpRequest httpProxy-authenticate: Basic, 'http://proxy.local',
               responseHandle: 'NONE', url: 'https://api.github.com/orgs/${orgName}'

You can send a request with accepted response codes

def response = httpRequest responseHandle: 'NONE', validResponseCodes: '200,404',
                           url: 'https://api.github.com/orgs/${orgName}'

You can send a request with accepted response content

def response = httpRequest responseHandle: 'STRING',
                           url: 'https://api.github.com/orgs/${orgName}',
                           validResponseCodes: '200,404', validResponseContent: 'token'

You can send a request with connection timeout

def response = httpRequest timeout: 30, url: 'https://api.github.com/orgs/${orgName}'

You can send a request where output is written to file

def response = httpRequest outputFile: 'readme.txt', url:'https://api.github.com/orgs/${orgName}'

You can send a request where response is printed on the console

def response = httpRequest consoleLogResponseBody: true,
               url:'https://api.github.com/orgs/${orgName}'

You can send a request without logging output — with logs turned off

def response = httpRequest quiet: true, url:'https://api.github.com/orgs/${orgName}'

You can handle response

def response = httpRequest responseHandle: 'LEAVE_OPEN',
                           url: "https://api.github.com/orgs/${orgName}"
response.close() // must call response.close() after a LEAVE_OPEN

You can use a Jenkins credential to authenticate the request

def response = httpRequest authenticate: 'my-jenkins-credential-id',
                           url: 'https://api.github.com/user/jenkinsci'

For details on the Pipeline features, use the Pipeline snippet generator in the Pipeline job configuration.

⚠️
Known Limitations

If Jenkins is restarted before the HTTP response comes back, the build will fail.

Building

The plugin can be built and tested locally using a Maven Docker container:

docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn test

Configure Global Settings

configure http request global

Configure Build Step in your Jenkins job

configure http request build step

HTTP Request Parameters

Parameters are escaped, which means if you try to pass another value inside a value, it will not happen.

In the example below, the key “name” will be passed with a value of “jenkins&os=linux”. Note that “os” is not a parameter - it is part of the value). At the HTTP server-side no parameter named “os” will exist.

🔥
Regarding Logging & Sensitive Information

Every execution will log all parameters. Be careful to not pass private information such as passwords or personal information.

log

Issues

Report issues and enhancements in the Jenkins issue tracker. Use the http-request-plugin component in the JENKINS project.

Contributing

Refer to our contribution guidelines.

License

Licensed under the MIT License.

More Repositories

1

jenkins

Jenkins automation server
Java
21,381
star
2

docker

Docker official jenkins repo
Dockerfile
6,144
star
3

pipeline-examples

A collection of examples, tips and tricks and snippets of scripting for the Jenkins Pipeline plugin
Groovy
4,117
star
4

blueocean-plugin

Blue Ocean is a reboot of the Jenkins CI/CD User Experience
Java
2,872
star
5

configuration-as-code-plugin

Jenkins Configuration as Code Plugin
Java
2,521
star
6

kubernetes-plugin

Jenkins plugin to run dynamic agents in a Kubernetes/Docker environment
Java
2,206
star
7

job-dsl-plugin

A Groovy DSL for Jenkins Jobs - Sweeeeet!
Groovy
1,851
star
8

pipeline-plugin

Obsolete home for Pipeline plugins
1,711
star
9

JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
Groovy
1,426
star
10

gitlab-plugin

A Jenkins plugin for interfacing with GitLab
Java
1,418
star
11

jenkinsfile-runner

A command line tool to run Jenkinsfile as a function
Java
1,114
star
12

java-client-api

A Jenkins API client for Java
Java
888
star
13

jenkins-scripts

Scripts in Groovy, shell, Ruby, Python, whatever for managing/interacting with Jenkins
Groovy
880
star
14

build-monitor-plugin

Jenkins Build Monitor Plugin
Java
722
star
15

slack-plugin

A Jenkins plugin for posting notifications to a Slack channel
Java
664
star
16

git-plugin

Git repository access for Jenkins jobs
Java
660
star
17

pipeline-model-definition-plugin

Groovy
557
star
18

ghprb-plugin

github pull requests builder plugin for Jenkins
Java
495
star
19

docker-workflow-plugin

Jenkins plugin which allows building, testing, and using Docker images from Jenkins Pipeline projects.
Java
492
star
20

docker-plugin

Jenkins Cloud Plugin that uses Docker
Java
482
star
21

docker-inbound-agent

Docker image for a Jenkins agent which can connect to Jenkins using TCP or Websocket protocols
PowerShell
466
star
22

helm-charts

Jenkins helm charts
Mustache
448
star
23

pipeline-aws-plugin

Jenkins Pipeline Step Plugin for AWS
Java
423
star
24

jenkins.rb

Deprecated, see https://www.jenkins.io/jep/7
Ruby
394
star
25

generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
Java
377
star
26

email-ext-plugin

Jenkins Email Extension Plugin
Java
338
star
27

dingtalk-plugin

Dingtalk for jenkins
Java
336
star
28

warnings-ng-plugin

Jenkins Warnings Plugin - Next Generation
Java
323
star
29

plugin-installation-manager-tool

Plugin Manager CLI tool for Jenkins
Java
301
star
30

mesos-plugin

Mesos Cloud Jenkins Plugin
Java
291
star
31

github-plugin

Jenkins GitHub plugin
Java
286
star
32

ec2-plugin

Jenkins ec2 plugin
Java
282
star
33

ssh-steps-plugin

Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery.
Java
273
star
34

ansicolor-plugin

Jenkins ANSI Color Plugin
Java
253
star
35

pipeline-utility-steps-plugin

Small, miscellaneous, cross platform utility steps for Jenkins Pipeline jobs.
Java
237
star
36

docker-agent

Base Docker image for Jenkins Agents
PowerShell
231
star
37

ansible-plugin

Jenkins Ansible plugin
Java
223
star
38

workflow-cps-global-lib-plugin

Java
223
star
39

lib-file-leak-detector

Java agent that detects file handle leak
Java
217
star
40

hashicorp-vault-plugin

Jenkins plugin to populate environment variables from secrets stored in HashiCorp's Vault.
Java
214
star
41

bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
Java
213
star
42

remoting

Jenkins Remoting module
Java
212
star
43

workflow-aggregator-plugin

211
star
44

gerrit-trigger-plugin

Java
209
star
45

android-emulator-plugin

Android Emulator plugin for Jenkins
Java
207
star
46

docker-slaves-plugin

A Jenkins plugin to run builds inside Docker containers
Java
205
star
47

pipeline-stage-view-plugin

Visualizes Jenkins pipelines
JavaScript
204
star
48

jenkinsfile-runner-github-actions

Jenkins single-shot pipeline execution in a GitHub Action POC
Shell
199
star
49

github-branch-source-plugin

GitHub Branch Source Plugin
Java
193
star
50

amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
Java
193
star
51

trilead-ssh2

Patched trilead-ssh2 used in Jenkins
Java
193
star
52

cucumber-reports-plugin

Jenkins plugin to generate cucumber-jvm reports
Java
192
star
53

docker-build-publish-plugin

Java
192
star
54

performance-plugin

Performance Test Running and Reporting for Jenkins CI
Java
188
star
55

jira-plugin

Jenkins jira plugin
Java
168
star
56

gitea-plugin

This plugin provides the Jenkins integration for Gitea.
Java
168
star
57

embeddable-build-status-plugin

Embed build status of Jenkins jobs in web pages
Java
167
star
58

stashnotifier-plugin

A Jenkins Plugin to notify Atlassian Stash|Bitbucket of build results
Java
166
star
59

docker-ssh-agent

Docker image for Jenkins agents connected over SSH
PowerShell
162
star
60

workflow-cps-plugin

Java
160
star
61

stapler

Stapler web framework
Java
154
star
62

kubernetes-pipeline-plugin

Kubernetes Pipeline is Jenkins plugin which extends Jenkins Pipeline to provide native support for using Kubernetes pods, secrets and volumes to perform builds
Java
154
star
63

tfs-plugin

Jenkins tfs plugin
Java
145
star
64

jep

Jenkins Enhancement Proposals
Shell
144
star
65

kubernetes-cd-plugin

A Jenkins plugin to deploy to Kubernetes cluster
Java
140
star
66

jacoco-plugin

Jenkins JaCoCo Plugin
Java
139
star
67

qy-wechat-notification-plugin

企业微信Jenkins构建通知插件
Java
138
star
68

swarm-plugin

Jenkins swarm plugin
Java
133
star
69

git-client-plugin

Git client API for Jenkins plugins
Java
130
star
70

subversion-plugin

Jenkins subversion plugin
Java
126
star
71

dependency-check-plugin

Jenkins plugin for OWASP Dependency-Check. Inspects project components for known vulnerabilities (e.g. CVEs).
Java
125
star
72

role-strategy-plugin

Jenkins Role-Strategy plugin
Java
120
star
73

groovy-sandbox

(Deprecated) Compile-time transformer to run Groovy code in a restrictive sandbox
Java
120
star
74

jenkins-design-language

Styles, assets, and React classes for Jenkins Design Language
TypeScript
116
star
75

acceptance-test-harness

Acceptance tests cases for Jenkins and its plugins based on selenium and docker.
Java
116
star
76

scm-sync-configuration-plugin

Jenkins scm-sync-configuration plugin
Java
116
star
77

gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
Java
115
star
78

git-parameter-plugin

Jenkins plugin for chosing Revision / Tag before build
Java
115
star
79

publish-over-ssh-plugin

Java
114
star
80

pipeline-as-yaml-plugin

Jenkins Pipeline As Yaml Plugin
Java
114
star
81

selenium-plugin

Jenkins selenium plugin
Java
112
star
82

docker-build-step-plugin

Java
111
star
83

code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
Java
111
star
84

jira-trigger-plugin

Triggers a build when a certain condition is matched in JIRA
Groovy
111
star
85

cobertura-plugin

Jenkins cobertura plugin
Java
110
star
86

gradle-plugin

Jenkins gradle plugin
Java
109
star
87

credentials-plugin

Provides Jenkins with extension points to securely store, manage, and bind credentials data to other Jenkins plugins, builds, pipelines, etc.
Java
107
star
88

jira-steps-plugin

Jenkins pipeline steps for integration with JIRA.
Java
104
star
89

artifactory-plugin

Jenkins artifactory plugin
Java
104
star
90

build-flow-plugin

A plugin to manage job orchestration
Groovy
103
star
91

throttle-concurrent-builds-plugin

Java
101
star
92

github-oauth-plugin

Jenkins authentication plugin using GitHub OAuth as the source.
Java
99
star
93

pipeline-graph-view-plugin

Java
99
star
94

promoted-builds-plugin

Jenkins Promoted Builds Plugin
Java
96
star
95

ssh-slaves-plugin

SSH Build Agents Plugin for Jenkins
Java
96
star
96

github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins
Java
93
star
97

jenkins-test-harness

Unit test framework for Jenkins core and its plugins
Java
92
star
98

opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
Java
90
star
99

localization-zh-cn-plugin

Chinese Localization for Jenkins
HTML
89
star
100

workflow-remote-loader-plugin

Load Pipeline scripts from remote locations (e.g. Git) - replaced by Pipeline: Groovy Libraries plugin
Java
88
star