Skip to content

Commit 3687b53

Browse files
committed
Updated the Jenkins cicd with golang
Signed-off-by: Achanandhi-M <[email protected]>
1 parent c1ce66a commit 3687b53

File tree

1 file changed

+84
-64
lines changed

1 file changed

+84
-64
lines changed

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

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,73 +29,97 @@ 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
}
51-
```
52-
53-
> **Note: if you are using `arm_64` as runner use below to download keploy binary**
5447

55-
`curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz --overwrite -C /tmp`
48+
```
5649

5750
### Example
5851

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:-
52+
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:-
6053

6154
```sh
6255
pipeline {
6356
agent any
6457
stages {
65-
stage('Keploy Tests') {
58+
stage('Install Dependencies') {
6659
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-
}
60+
sh 'sudo apt-get update && sudo apt-get install -y curl kmod linux-headers-generic bpfcc-tools git golang-go'
61+
}
62+
}
63+
stage('Clone and Setup App') {
64+
steps {
65+
sh '''
66+
rm -rf samples-go
67+
git clone 'https://github.com/keploy/samples-go'
68+
cd gin-mongo
69+
go mod tidy
70+
'''
71+
}
72+
}
73+
stage('Install Keploy') {
74+
steps {
75+
sh '''
76+
curl --silent -O -L https://keploy.io/install.sh && bash install.sh
77+
'''
78+
}
79+
}
80+
stage('Prepare eBPF Hooks') {
81+
steps {
82+
sh '''
83+
sudo mkdir -p /sys/kernel/debug
84+
sudo mkdir -p /sys/kernel/tracing
85+
sudo mount -t debugfs nodev /sys/kernel/debug || true
86+
sudo mount -t tracefs nodev /sys/kernel/tracing || true
87+
'''
88+
}
89+
}
90+
stage('Run Keploy Tests') {
91+
steps {
92+
sh '''
93+
cd gin-mongo
94+
sudo -E keploy test -c "go run main.go handler.go" --disableANSI
95+
'''
8596
}
8697
}
8798
}
8899
}
100+
89101
```
90102

103+
### 📝 Note
104+
105+
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?"_ 😅
106+
107+
Don’t worry — these are just there because **Keploy uses eBPF** (a cool Linux feature) to trace your app’s behavior.
108+
109+
So we install `kmod`, `linux-headers-generic`, and `bpfcc-tools` to make that tracing possible.
110+
111+
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.
112+
113+
No black magic. Just some low-level Linux stuff helping your tests run like magic! 🪄✨
114+
91115
We would output something like below:-
92116

93117
```sh
94118
Started by `user admin`
95119

96120
...
97121

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

100124
▓██▓▄
101125
▓▓▓▓██▓█▓▄
@@ -107,43 +131,39 @@ Started by `user admin`
107131
▓▌ ▐█▌ █▌
108132
109133

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
134+
version: 2.5.2
124135

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

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

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

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

135-
--------------------------------------------------------------------
156+
--------------------------------------------------------------------
136157

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

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}
160+
<=========================================>
161+
TESTRUN SUMMARY. For test-set: "test-set-0"
162+
Total tests: 2
163+
Total test passed: 2
164+
Total test failed: 0
165+
Time Taken: "5.02 s"
166+
<=========================================>
147167
```
148168
149169
_And... voila! You have successfully integrated keploy in Jenkins CI/CD pipeline 🌟_

0 commit comments

Comments
 (0)