Skip to content

Commit

Permalink
Merge pull request #13 from martinda/feature/workflow-integration
Browse files Browse the repository at this point in the history
Make plugin compatible with Workflow
  • Loading branch information
janario committed May 20, 2016
2 parents 34e6c5f + 98108c9 commit 672e036
Show file tree
Hide file tree
Showing 52 changed files with 3,038 additions and 406 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ target/

work/*
*.iml
.idea/*
.idea/*

# Vim files
Session.vim
*.swp
66 changes: 60 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
This plugin does a HTTP/HTTPS request to a speficied URL with the build parameters automatically
part of the payload as key/value pairs.
# Http Request Plugin for Jenkins

It can be configured whether GET or POST (default) should be used as HTTP method, as well
as if the status return code of the response marks the build as failed (default) or is ignored.
You can specify different username / password pairs in the global configuration to support
authenticated HTTP/HTTPS requests, which you then refer to from your build configuration.
This plugin sends a HTTP/HTTPS request to a user speficied URL.

## Features

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

* Programmable HTTP method: GET, POST, PUT, 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 From 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

### Basic plugin features

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:

```groovy
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:

```groovy
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:

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

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.
90 changes: 80 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>

<version>1.509.4</version>
<version>2.3</version>
</parent>

<artifactId>http_request</artifactId>
<version>1.8.9-SNAPSHOT</version>
<packaging>hpi</packaging>
Expand All @@ -15,8 +14,14 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
<commons.version>1.10</commons.version>
<httpcomponents.version>4.5.1</httpcomponents.version>
<script-security.version>1.17</script-security.version>
<jenkins.version>1.609.3</jenkins.version>
<workflow.version>1.10</workflow.version>
</properties>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
Expand All @@ -30,20 +35,79 @@
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx320m</argLine>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpcomponents.version}</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>${script-security.version}</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
</dependency>

<!-- Test framework -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>${httpcomponents.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.2</version>
<version>${httpcomponents.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

</dependencies>

<scm>
<connection>scm:git:ssh://github.com/jenkinsci/http-request-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/http-request-plugin.git</developerConnection>
Expand All @@ -56,4 +120,10 @@
<email>janarioliver@gmail.com</email>
</developer>
</developers>
<contributors>
<contributor>
<name>Martin d'Anjou</name>
<email>martin.danjou14@gmail.com</email>
</contributor>
</contributors>
</project>
Loading

0 comments on commit 672e036

Please sign in to comment.