Giter Site home page Giter Site logo

jsearby / http-request-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jenkinsci/http-request-plugin

0.0 1.0 0.0 641 KB

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

Home Page: https://plugins.jenkins.io/http_request

License: MIT License

Java 95.91% HTML 4.09%

http-request-plugin's Introduction

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 as a job execution in Jenkins and depending of the HTTP response the job could be marked as failed (configurable). For example, responses such as 404 and 500 could make the job fail. When a job fails it will log the response to help identify the problem. The request may be as an HTTP GET or POST mode, by choosing the HTTP mode. If it was not informed, it will use the default from global settings whose default is POST.

Features

The following features are available in both Pipeline and traditional project types:

  • Programmable HTTP method: GET, POST, PUT, PATCH, DELETE, or HEAD

  • Programmable range of expected response codes (a response code outside the range fails the build)

  • Supports Basic Authentication (see global configuration)

  • Supports Form Authentication (see global configuration)

  • You can specify a string that must be present in the response (if the string is not present, the build fails)

  • You can set a connection timeout limit (build fails if timeout is exceeded)

  • You can set an "Accept" header

  • You can set a "Content-Type" header

  • You can set any custom header

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 and content programmatically:

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

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 can also set custom headers:

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

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.

http-request-plugin's People

Contributors

janario avatar martinda avatar basil avatar darxriggs avatar oleg-nenashev avatar james-chapman avatar offa avatar holleymcfly avatar timja avatar dependabot[bot] avatar cpoenisch avatar clnl-nykredit avatar kmadel avatar lyca avatar nikos avatar olivergondza avatar ebceeb avatar mrmaus avatar cesartl avatar daniel-beck-bot avatar lexmark-haputman avatar issc29 avatar konrad-krakowiak avatar nrayapati avatar onyimatics avatar pawel-cieslak avatar pdalpra avatar pieterbreed avatar llamahunter avatar bezda avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.