Skip to content

Commit b723f04

Browse files
authored
feat: updated the Jenkins CI/CD pipeline for Golang. (#514)
* Updated the Jenkins cicd with golang Signed-off-by: Achanandhi-M <[email protected]> * ARM support added for jenkins pipeline Signed-off-by: Achanandhi-M <[email protected]> --------- Signed-off-by: Achanandhi-M <[email protected]>
1 parent c1ce66a commit b723f04

File tree

1 file changed

+84
-60
lines changed

1 file changed

+84
-60
lines changed

versioned_docs/version-2.0.0/ci-cd/jenkins.md

+84-60
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,22 @@ jenkins ALL=(ALL) NOPASSWD: ALL
2929

3030
## Create a Pipeline
3131

32-
Use the below template to create a Pipeline via script : -
32+
Use the template below to install Keploy in your Jenkins pipeline using a script : -
3333

3434
```sh
3535
pipeline {
3636
agent any
3737
stages {
38-
stage('Keploy Tests') {
38+
stage('Install Keploy') {
3939
steps {
40-
// Download and prepare Keploy binary
41-
sh "curl --silent --location 'https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz' | tar xz --overwrite -C /tmp"
42-
sh "mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploy"
43-
44-
// Install application dependencies && Run the keploy test suite
45-
46-
sudo -E keploy test -c <CMD_TO_RUN_YOUR_APP>
40+
sh '''
41+
curl --silent -O -L https://keploy.io/install.sh && bash install.sh
42+
'''
4743
}
4844
}
4945
}
5046
}
47+
5148
```
5249

5350
> **Note: if you are using `arm_64` as runner use below to download keploy binary**
@@ -56,46 +53,77 @@ pipeline {
5653

5754
### Example
5855

59-
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 [express-mongoose](https://github.com/keploy/samples-typescript/tree/main/express-mongoose) sample-application, steps in our `script` would look like below:-
56+
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](https://github.com/keploy/samples-go/tree/main/gin-mongo) sample-application, steps in our `script` would look like below:-
6057

6158
```sh
6259
pipeline {
6360
agent any
6461
stages {
65-
stage('Keploy Tests') {
62+
stage('Install Dependencies') {
6663
steps {
67-
68-
// Clone the repository
69-
git branch: 'main', url: 'https://github.com/keploy/samples-typescript.git'
70-
71-
// Download and prepare Keploy binary
72-
sh "curl --silent --location 'https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz' | tar xz --overwrite -C /tmp"
73-
sh "mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploy"
74-
75-
// switch to the directory where keploy folder is present
76-
dir('express-mongoose'){
77-
78-
// Make sure you have NPM in host machine and Install application dependencies.
79-
80-
sh"""
81-
npm install
82-
sudo -E keploy test -c "npm run start" --disableANSI
83-
"""
84-
}
64+
sh 'sudo apt-get update && sudo apt-get install -y curl kmod linux-headers-generic bpfcc-tools git golang-go'
65+
}
66+
}
67+
stage('Clone and Setup App') {
68+
steps {
69+
sh '''
70+
rm -rf samples-go
71+
git clone 'https://github.com/keploy/samples-go'
72+
cd gin-mongo
73+
go mod tidy
74+
'''
75+
}
76+
}
77+
stage('Install Keploy') {
78+
steps {
79+
sh '''
80+
curl --silent -O -L https://keploy.io/install.sh && bash install.sh
81+
'''
82+
}
83+
}
84+
stage('Prepare eBPF Hooks') {
85+
steps {
86+
sh '''
87+
sudo mkdir -p /sys/kernel/debug
88+
sudo mkdir -p /sys/kernel/tracing
89+
sudo mount -t debugfs nodev /sys/kernel/debug || true
90+
sudo mount -t tracefs nodev /sys/kernel/tracing || true
91+
'''
92+
}
93+
}
94+
stage('Run Keploy Tests') {
95+
steps {
96+
sh '''
97+
cd gin-mongo
98+
sudo -E keploy test -c "go run main.go handler.go" --disableANSI
99+
'''
85100
}
86101
}
87102
}
88103
}
104+
89105
```
90106

107+
### 📝 Note
108+
109+
Did you notice some weird stuff in the pipeline? Like `kmod`, `linux-headers`, `/sys/kernel/debug`...and thought, _"Wait, am I hacking the kernel or something?"_ 😅
110+
111+
Don’t worry — these are just there because **Keploy uses eBPF** (a cool Linux feature) to trace your app’s behavior.
112+
113+
So we install `kmod`, `linux-headers-generic`, and `bpfcc-tools` to make that tracing possible.
114+
115+
Some CI systems don’t have `/sys/kernel/debug` and `/sys/kernel/tracing` by default, so we create them and mount `debugfs` and `tracefs` — it’s like giving Keploy the **backstage pass** it needs to watch your app in action.
116+
117+
No black magic. Just some low-level Linux stuff helping your tests run like magic! 🪄✨
118+
91119
We would output something like below:-
92120

93121
```sh
94122
Started by `user admin`
95123

96124
...
97125

98-
+ sudo -E keploy test -c npm run start --disableANSI
126+
sudo -E keploy test -c go run main.go handler.go --disableANSI
99127

100128
▓██▓▄
101129
▓▓▓▓██▓█▓▄
@@ -107,43 +135,39 @@ Started by `user admin`
107135
▓▌ ▐█▌ █▌
108136
109137

110-
version: 2.1.0-alpha23
111-
112-
🐰 Keploy: 2024-06-05T14:50:12+05:30 INFO config file not found; proceeding with flags only
113-
🐰 Keploy: 2024-06-05T14:50:12+05:30 WARN Delay is set to 5 seconds, incase your app takes more time to start use --delay to set custom delay
114-
🐰 Keploy: 2024-06-05T14:50:12+05:30 INFO Example usage: keploy test -c "/path/to/user/app" --delay 6
115-
🐰 Keploy: 2024-06-05T14:50:12+05:30 INFO GitHub Actions workflow file generated successfully {"path": "/githubactions/keploy.yml"}
116-
🐰 Keploy: 2024-06-05T14:50:13+05:30 INFO keploy initialized and probes added to the kernel.
117-
🐰 Keploy: 2024-06-05T14:50:13+05:30 INFO Java detected and CA already exists {"path": "/usr/lib/jvm/java-17-openjdk-arm64/lib/security/cacerts"}
118-
🐰 Keploy: 2024-06-05T14:50:13+05:30 INFO Java detected and CA already exists {"path": "/usr/lib/jvm/java-17-openjdk-arm64/lib/security/cacerts"}
119-
🐰 Keploy: 2024-06-05T14:50:14+05:30 INFO Keploy has taken control of the DNS resolution mechanism, your application may misbehave if you have provided wrong domain name in your application code.
120-
🐰 Keploy: 2024-06-05T14:50:14+05:30 INFO Proxy started at port:16789
121-
🐰 Keploy: 2024-06-05T14:50:14+05:30 INFO running {"test-set": "test-set-0"}
122-
🐰 Keploy: 2024-06-05T14:50:14+05:30 INFO starting TCP DNS server at addr :26789
123-
🐰 Keploy: 2024-06-05T14:50:14+05:30 INFO starting UDP DNS server at addr :26789
138+
version: 2.5.2
124139

125-
126-
> node src/app.js
140+
2025-04-18T04:06:50.413Z INFO provider/cmd.go:504 Color encoding is disabled
141+
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
142+
2025-04-18T04:06:50.413Z INFO provider/cmd.go:730 Example usage: keploy test -c "/path/to/user/app" --delay 6
143+
2025-04-18T04:06:50.413Z WARN replay/replay.go:140 go language detected. please use --language to manually set the language if needed
144+
2025-04-18T04:06:50.413Z WARN golang/utils.go:28 cover flag not found in command, skipping coverage calculation
145+
2025-04-18T04:06:51.104Z INFO hooks/hooks.go:436 keploy initialized and probes added to the kernel.
127146

128-
Listening on port 8000
129-
Connected to MongoDB
147+
[GIN-debug] GET /:param --> main.GetURL (3 handlers)
148+
[GIN-debug] POST /url --> main.PutURL (3 handlers)
149+
2025-04-18T04:06:57.585Z INFO pkg/util.go:123 starting test for of {"test case": "[test-1]", "test set": "[test-set-0]"}
150+
[GIN] 2025/04/18 - 04:06:57 | 200 | 2.109927ms | ::1 | POST "/url"
151+
Testrun passed for testcase with id: "test-1"
130152

131-
🐰 Keploy: 2024-06-05T14:50:19+05:30 INFO starting test for of {"test case": "test-1", "test set": "test-set-0"}
153+
--------------------------------------------------------------------
132154

133-
Testrun passed for testcase with id: "test-1"
155+
2025-04-18T04:06:57.588Z INFO replay/replay.go:717 result {"testcase id": "[test-1]", "testset id": "[test-set-0]", "passed": "[true]"}
156+
2025-04-18T04:06:57.593Z INFO pkg/util.go:123 starting test for of {"test case": "[test-2]", "test set": "[test-set-0]"}
157+
[GIN] 2025/04/18 - 04:06:57 | 303 | 852.601µs | ::1 | GET "/Lhr4BWAi"
158+
Testrun passed for testcase with id: "test-2"
134159

135-
--------------------------------------------------------------------
160+
--------------------------------------------------------------------
136161

137-
🐰 Keploy: 2024-06-05T14:50:19+05:30 INFO result {"testcase id": "test-1", "testset id": "test-set-0", "passed": "true"}
162+
2025-04-18T04:06:57.597Z INFO replay/replay.go:717 result {"testcase id": "[test-2]", "testset id": "[test-set-0]", "passed": "[true]"}
138163

139-
<=========================================>
140-
TESTRUN SUMMARY. For test-set: "test-set-0"
141-
Total tests: 1
142-
Total test passed: 1
143-
Total test failed: 0
144-
<=========================================>
145-
...
146-
🐰 Keploy: 2024-06-05T14:50:19+05:30 INFO test run completed {"passed overall": true}
164+
<=========================================>
165+
TESTRUN SUMMARY. For test-set: "test-set-0"
166+
Total tests: 2
167+
Total test passed: 2
168+
Total test failed: 0
169+
Time Taken: "5.02 s"
170+
<=========================================>
147171
```
148172
149173
_And... voila! You have successfully integrated keploy in Jenkins CI/CD pipeline 🌟_

0 commit comments

Comments
 (0)