Using HTTP Requests in CD Pipelines

Updated 1 month ago by Michael Cretzman

You can use the HTTP step to run HTTP methods containing URLs, methods, headers, assertions, and variables. It helps you avoid having script cURL commands for simple REST calls.

The most common use of the HTTP step is to run a health check post-deployment. For example, make sure that an HTTP or IP endpoint, such as a load balancer, is properly exposed.

Other common uses are:

  • Making a call to a third-party system to gather deployment information, such as a Nexus IQ scan.
  • Open Policy Agent (OPA) policy agent call.
  • General HTTP testing calls to the deployed application.

This topic describes how to use the HTTP step. For comprehensive details on each setting, see HTTP Step Reference.

Looking for the Harness REST API? See API Quickstart.

In this topic:

Before You Begin

Step 1: Add the HTTP step

You can add the HTTP step to any CD Pipeline stage independent of deployment strategy.

In your Harness Pipeline stage, in Execution, click Add Step.

Click HTTP. The HTTP step appears.

Step 2: Name and Timeout

Enter a name for the step. You'll use this name to reference step settings in other steps.

For example, if the step name is HTTP and you want to reference the URL entered in its URL setting, you'd use:

<+pipeline.stages.tooltips.spec.execution.steps.HTTP.spec.url>

In Timeout, enter a timeout for this step.You can use:

  • w for weeks
  • d for days
  • h for hours
  • m for minutes
  • s for seconds
  • ms for milliseconds

The maximum is 53w.Timeouts are set at the Pipeline level also.

Step 3: URL for HTTP Call

In URL, enter a URL for the call. It must include the http:// scheme.

You can use a Fixed Value, Runtime Input, or Expression.

You can use Harness variables, too. For example, if the Service name matches the domain name of the HTTP address, you can use http://<+service.name>/....

Step 4: HTTP Method

In HTTP Method, select the method for the call.

Harness supports the following HTTP methods:

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD
  • OPTIONS

Option: Request Body

In Body, you can enter the body of the HTTP payload to send to the URL.

You can use a Fixed Value, Runtime Input, or Expression.

You can use Harness variables, too.

Option: Assertion

The assertion is used to validate the incoming response. For example, if you wanted to check the health of an HTTP connection, you could use the assertion <+httpResponseCode> == 200.

The expression <+httpResponseCode> == 200 will evaluate to true if the HTTP call returns a 200 code.

Expressions can use the following aliases to refer to the HTTP responses, URL, and method:

  • <+httpResponseCode>
  • <+httpUrl>
  • <+httpMethod>
  • <+httpResponseBody>

You can use a Fixed Value, Runtime Input, or Expression.

You can use Harness variables, too.

Option: Headers

Headers are key:value pairs. For example:

  • Content-Type: application/json
  • Content-Type: text/html

You can use a Fixed Value, Runtime Input, or Expression.

You can use Harness variables, too.

You can reference Harness secrets in the Value setting, too.

For example, in Key, enter Token .

In Value, enter <+secrets.getValue("aws-playground_AWS_secret_key")>.

Option: Output Variables

You can create output variables and reference them in other steps in the stage. The Value setting can contain any HTTP step input, output, or response information.

To reference the value of the output variable in another step using its fully-qualified name (FQN).

For example, here's a variable example with the value 1234. The step name is GET.

Save the step and then click Variables.

In the Variables drawer, copy the example variable.

In another step, like a Shell Script step, paste the FQN.

The FQN will resolve to the variable value at execution runtime.

You can also use ​JSON and XML functors in the values for the output variable. For example, <+json.select("data.attributes.version_pins.mvn-service://new-construction-api", httpResponseBody)>.

See JSON and XML Functors.

Review: Simulate Load by Running Steps in Parallel

You can use multiple HTTP steps in parallel to simulate load.

Simply create a Step Group and add multiple HTTP steps with the same URL pointing to your service.

The steps are executed in parallel and simulate load.

You can add multiple steps to the group quickly using YAML. Just paste additional steps into the Step Group. Be sure to rename each step. Here's an example:

...
- stepGroup:
name: Simulate Load
identifier: Simulate_Load
steps:
- parallel:
- step:
type: Http
name: Load 1
identifier: Load_1
spec:
url: http://example.com
method: GET
headers: []
outputVariables: []
timeout: 10s
- step:
type: Http
name: Load 2
identifier: Load_2
spec:
url: http://example.com
method: GET
headers: []
outputVariables: []
timeout: 10s
- step:
type: Http
name: Load 3
identifier: Load_3
spec:
url: http://example.com
method: GET
headers: []
outputVariables: []
timeout: 10s
failureStrategies: []
spec: {}
...

See Also


Please Provide Feedback