Integrating with Jenkins
Keploy can integrated with Jenkins to ensure continuous testing as part of your CI/CD pipeline.
Prerequisites
- Jenkins installed and running
- A Keploy account (a free one is enough) and its API key, saved as a Secret text credential with ID
keploy-api-key(Manage Jenkins → Credentials). In CI, Keploy signs in with the key inKEPLOY_API_KEY. - Sudo access with
"NOPASSWORD"viajenkins ALL=(ALL) NOPASSWD: ALL.
Open terminal and runsudo visudo command to open the sudoers file and add the below line at the end of the file.
jenkins ALL=(ALL) NOPASSWD: ALL
Create a Pipeline
Use the template below to install Keploy in your Jenkins pipeline using a script : -
pipeline {
agent any
stages {
stage('Install Keploy') {
steps {
sh '''
curl --silent -O -L https://keploy.io/install.sh && bash install.sh
'''
}
}
}
}
Example
Now that we have Keploy installed, and all ready, we need switch to path where keploy folder is present in our application and install all the application related dependencies. Since we are using gin-mongo sample-application, steps in our script would look like below:-
pipeline {
agent any
stages {
stage('Install Dependencies') {
steps {
sh 'sudo apt-get update && sudo apt-get install -y curl kmod linux-headers-generic bpfcc-tools git golang-go'
}
}
stage('Clone and Setup App') {
steps {
sh '''
rm -rf samples-go
git clone 'https://github.com/keploy/samples-go'
cd gin-mongo
go mod tidy
'''
}
}
stage('Install Keploy') {
steps {
sh '''
curl --silent -O -L https://keploy.io/install.sh && bash install.sh
'''
}
}
stage('Prepare eBPF Hooks') {
steps {
sh '''
sudo mkdir -p /sys/kernel/debug
sudo mkdir -p /sys/kernel/tracing
sudo mount -t debugfs nodev /sys/kernel/debug || true
sudo mount -t tracefs nodev /sys/kernel/tracing || true
'''
}
}
stage('Run Keploy Tests') {
steps {
withCredentials([string(credentialsId: 'keploy-api-key', variable: 'KEPLOY_API_KEY')]) {
sh '''
cd gin-mongo
sudo -E keploy test -c "go run main.go handler.go" --disableANSI
'''
}
}
}
}
}
📝 Note
Did you notice some weird stuff in the pipeline? Like kmod, linux-headers, /sys/kernel/debug
Don’t worry — these are just there because on Linux, Keploy uses eBPF (a cool Linux feature) to trace your app’s behavior.
So we install kmod, linux-headers-generic, and bpfcc-tools to make that tracing possible.
Some CI systems don’t have /sys/kernel/debug and /sys/kernel/tracing by default, so we create them and mount debugfs and tracefs
We would output something like below:-
Started by `user admin`
...
sudo -E keploy test -c go run main.go handler.go --disableANSI
▓██▓▄
▓▓▓▓██▓█▓▄
████████▓▒
▀▓▓███▄ ▄▄ ▄ ▌
▄▌▌▓▓████▄ ██ ▓█▀ ▄▌▀▄ ▓▓▌▄ ▓█ ▄▌▓▓▌▄ ▌▌ ▓
▓█████████▌▓▓ ██▓█▄ ▓█▄▓▓ ▐█▌ ██ ▓█ █▌ ██ █▌ █▓
▓▓▓▓▀▀▀▀▓▓▓▓▓▓▌ ██ █▓ ▓▌▄▄ ▐█▓▄▓█▀ █▓█ ▀█▄▄█▀ █▓█
▓▌ ▐█▌ █▌
▓
version: 2.5.2
2025-04-18T04:06:50.413Z INFO provider/cmd.go:504 Color encoding is disabled
2025-04-18T04:06:50.413Z WARN provider/cmd.go:726 Delay is set to 5 seconds, incase your app takes more time to start use --delay to set custom delay
2025-04-18T04:06:50.413Z INFO provider/cmd.go:730 Example usage: keploy test -c "/path/to/user/app" --delay 6
2025-04-18T04:06:50.413Z WARN replay/replay.go:140 go language detected. please use --language to manually set the language if needed
2025-04-18T04:06:50.413Z WARN golang/utils.go:28 cover flag not found in command, skipping coverage calculation
2025-04-18T04:06:51.104Z INFO hooks/hooks.go:436 keploy initialized and probes added to the kernel.
[GIN-debug] GET /:param --> main.GetURL (3 handlers)
[GIN-debug] POST /url --> main.PutURL (3 handlers)
2025-04-18T04:06:57.585Z INFO pkg/util.go:123 starting test for of {"test case": "[test-1]", "test set": "[test-set-0]"}
[GIN] 2025/04/18 - 04:06:57 | 200 | 2.109927ms | ::1 | POST "/url"
Testrun passed for testcase with id: "test-1"
--------------------------------------------------------------------
2025-04-18T04:06:57.588Z INFO replay/replay.go:717 result {"testcase id": "[test-1]", "testset id": "[test-set-0]", "passed": "[true]"}
2025-04-18T04:06:57.593Z INFO pkg/util.go:123 starting test for of {"test case": "[test-2]", "test set": "[test-set-0]"}
[GIN] 2025/04/18 - 04:06:57 | 303 | 852.601µs | ::1 | GET "/Lhr4BWAi"
Testrun passed for testcase with id: "test-2"
--------------------------------------------------------------------
2025-04-18T04:06:57.597Z INFO replay/replay.go:717 result {"testcase id": "[test-2]", "testset id": "[test-set-0]", "passed": "[true]"}
<=========================================>
TESTRUN SUMMARY. For test-set: "test-set-0"
Total tests: 2
Total test passed: 2
Total test failed: 0
Time Taken: "5.02 s"
<=========================================>
And... voila! You have successfully integrated keploy in Jenkins CI/CD pipeline 🌟
Hope this helps you out, if you still have any questions, reach out to us .
Running cloud replay in CI
Keploy cloud replay re-runs test sets that were recorded from a Kubernetes deployment. It works with both Keploy Cloud and a self-hosted Keploy setup — the command is the same either way.
How authentication works
The CLI reads the KEPLOY_API_KEY environment variable automatically. You do not need to pass it as a flag or log in through a browser.
- Locally:
export KEPLOY_API_KEY="<your-api-key>"before running the command. - In CI: add the key to Jenkins' credentials store so the system injects it as an environment variable at runtime. Never hard-code it in your Jenkins pipeline file.
In Jenkins, go to Manage Jenkins → Credentials, add a Secret text credential with ID keploy-api-key, and use withCredentials in your pipeline to bind it to KEPLOY_API_KEY.
Steps
- Add
KEPLOY_API_KEYas a Secret text credential in Jenkins (Manage Jenkins → Credentials). - Install Keploy on the agent.
- Run
keploy cloud replaywith your application and cluster details.
Install Keploy with the same script as above:
curl --silent -O -L https://keploy.io/install.sh && bash install.sh. WithKEPLOY_API_KEYset, Keploy signs in with your key.
Example: Jenkins Declarative Pipeline
pipeline {
agent any
stages {
stage('Install Keploy') {
steps {
sh '''
curl --silent -O -L https://keploy.io/install.sh && bash install.sh
'''
}
}
stage('Cloud replay') {
steps {
withCredentials([string(credentialsId: 'keploy-api-key', variable: 'KEPLOY_API_KEY')]) {
sh '''
keploy cloud replay \
--app "<NAMESPACE>.<DEPLOYMENT>" \
--cluster "<CLUSTER>" \
--namespace "<NAMESPACE>" \
--delay <DELAY>
'''
}
}
}
}
}
Replace <NAMESPACE>, <DEPLOYMENT>, <CLUSTER>, and <DELAY> with your own values. Set <DELAY> to cover your application's startup time (in seconds).
withCredentialsbinds the Jenkins secret toKEPLOY_API_KEYonly for the duration of that stage — the CLI picks it up automatically.
Related
- Integrating with GitHub CI — the GitHub equivalent.
- Integrating with GitLab CI — the GitLab equivalent.
- API Test Setup for GitHub CI/CD — API-suite CI setup.