Integrate Gatling with Gitlab CI/CD
Add performance testing to your Gitlab CI/CD pipeline with Gatling Enterprise.
Performance testing is a critical component of modern software development. By integrating Gatling Enterprise with Gitlab CI/CD, you incorporate performance testing into your development workflow, ensuring your applications meet performance standards before reaching production.
Prerequisites
- Gatling version
3.13.5
or higher - An account on Gatling Entreprise
- Clone this code and cd into the
articles/gitlabintegration
folder.
Test Creation
Create the Scenario
Let’s create a simple scenario that loads our e-commerce demo website.
import {
simulation,
scenario,
atOnceUsers,
global,
} from "@gatling.io/core";
import { http } from "@gatling.io/http";
export default simulation((setUp) => {
const httpProtocol = http
.baseUrl("https://ecomm.gatling.io")
const GetHome = scenario("Ecommerce").exec(
http("Get home").get("/")
);
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;
import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;
public class EcommerceGitlabCISampleJava extends Simulation {
HttpProtocolBuilder httpProtocol =
http.baseUrl("https://ecomm.gatling.io")
.acceptHeader("application/json")
.contentTypeHeader("application/json");
ScenarioBuilder GetHome = scenario("Ecommerce")
.exec(http("Get home")
.get("/"));
import io.gatling.core.scenario.Simulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class EcommerceGitlabCISampleScala extends Simulation {
val httpProtocol = http
.baseUrl("https://ecomm.gatling.io")
.acceptHeader("application/json")
.contentTypeHeader("application/json")
val GetHome = scenario("Ecommerce")
.exec(http("Get home").get("/"))
import io.gatling.javaapi.core.*
import io.gatling.javaapi.http.*
import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.http.HttpDsl.*
class EcommerceGitlabCISampleKotlin : Simulation() {
val httpProtocol = http
.baseUrl("https://ecomm.gatling.io")
.acceptHeader("application/json")
.contentTypeHeader("application/json")
val GetHome = scenario("Ecommerce")
.exec(http("Get home").get("/"))
Generate the user and assertions
We start with a single user to verify our simulation works correctly. Then we add assertions to validate our test results. In this example, we check that more than 90% of requests are successful.
setUp(
GetHome.injectOpen(atOnceUsers(1)),
).assertions(
global().successfulRequests().percent().gt(90.0)
).protocols(httpProtocol);
{
setUp(
GetHome.injectOpen(atOnceUsers(1))
).assertions(
global().successfulRequests().percent().gt(90.0)
).protocols(httpProtocol);
}
setUp(
GetHome.inject(atOnceUsers(1))
).assertions(
global.successfulRequests.percent.gt(90.0)
).protocols(httpProtocol)
init {
setUp(
GetHome.injectOpen(atOnceUsers(1))
).assertions(
global().successfulRequests().percent().gt(90.0)
).protocols(httpProtocol)
}
Gatling Enterprise
Deploy to Gatling Enterprise
Now that we have our test ready, we need to deploy the package to Gatling Enterprise.
Create the Simulation
Next, we create a simulation in Gatling Enterprise using our deployed package.
Copy Your Simulation ID
Make sure to copy the simulation Id
by clicking the three dots menu next to your simulation name, as we use this ID in subsequent steps.
Create an API Key
To enable Gitlab CI/CD to interact with Gatling Enterprise and trigger simulations, you need to generate an API key.
With Gatling Enterprise configured, we proceed to setting up our Gitlab CI/CD pipeline.
Gitlab CI/CD
Set up the Secrets and Environment
To run simulations from Gitlab CI/CD, you first need to configure a secure API token. Follow these steps to set up the required variable:
- Navigate to your GitLab repository
- Access the
Settings
menu - Select
CI/CD
from the sidebar - Click on
Variables
- Press the
Add variable
button - Choose
Masked and hidden
forVisibility
- Enter
GATLING_ENTERPRISE_API_TOKEN
as theKey
- Paste your API token as the
Value
If you need to generate a new API token, follow our guide here.
Configure the Pipeline
Let’s set up a basic Gitlab CI/CD pipeline that runs your performance tests. The pipeline configuration triggers a simulation using the provided simulation Id
.
Here’s the pipeline configuration (.gitlab-ci.yml):
stages:
- load-test
run-gatling-enterprise:
stage: load-test
image:
name: gatlingcorp/enterprise-runner:1
entrypoint: ['']
script:
- gatlingEnterpriseStart
variables:
SIMULATION_ID: '00000000-0000-0000-0000-000000000000'
For advanced pipeline customization options, check our Gitlab CI/CD documentation.
Run the Pipeline
With everything configured, you can now trigger the pipeline from GitLab CI/CD. Provide your simulation Id
when running the pipeline, and you are able to monitor the test execution both in GitLab and Gatling Enterprise.
Conclusion
This integration streamlines the testing process and enhances collaboration between development teams. With Gatling Enterprise and Gitlab CI/CD, you create a pipeline that continuously monitors your application’s performance, making it easier to maintain high standards of application quality throughout the development lifecycle.