JetBrains Space
 

Send HTTP Requests

Last modified: 15 December 2023

Sending an HTTP request to an external service is a common CI/CD task. In Automation, this task can be generally solved as follows:

  1. Reference a Maven library that provides an HTTP client of your choice (the library must be hosted on Maven Central).

  2. Use the client to send requests in a kotlinScript code block.

For example, the following script gets a random joke from icanhazdadjoke.com and prints it to the job's log. In this example we use the OkHttp client.

More complex example: A build script generates a log file with the time log-message data. The task is to send this log to an external service in the JSON format. The service requires authentication with a permanent token. The token is stored in the project's Secrets & Parameters. In this example we use the Ktor HTTP client.