Chaos Engineering: How to Create an Automated Chaos Gauntlet using Gremlin & Jenkins

Step 1 — Add Gremlin API Keys To Jenkins

Step 2 — Create your Chaos Staging Pipeline

Add your source (github project)
Add your pipeline script (see the example below)
pipeline {
agent none
environment {
ATTACK_ID = ''
GREMLIN_API_KEY = credentials('gremlin-api-key')
}
parameters {
string(name: 'CPU_LENGTH', defaultValue: '1000', description: 'Duration of CPU attack')
string(name: 'CPU_PERCENT', defaultValue: '50', description: 'Percentage of CPU attack')
string(name: 'CPU_CORE', defaultValue: '4', description: 'Number of cores to impact')
string(name: 'TARGET_IDENTIFIER', defaultValue: '172.31.56.245', description: 'Host to target')
}
stages {
stage('Chaos Staging Gauntlet') {
agent any
steps {
script {
ATTACK_ID = sh (
script: "curl -s -H 'Content-Type: application/json' -H 'X-Gremlin-Agent: jenkins' -H 'Authorization: Key ${GREMLIN_API_KEY}' https://api.gremlin.com/v1/attacks/new --data '{ \"command\": { \"type\": \"cpu\", \"args\": [\"-c\", \"$CPU_CORE\", \"-l\", \"$CPU_LENGTH\", \"-p\", \"$CPU_PERCENT\"] },\"target\": { \"type\": \"Exact\", \"hosts\" : { \"ids\": [\"$TARGET_IDENTIFIER\"] } } }' --compressed",
returnStdout: true
).trim()
echo "see your attack at https://app.gremlin.com/attacks/${ATTACK_ID}"
}
}
}
stage('Observe and/or Halt Chaos') {
agent any
input {
message 'Do you want to halt attack?'
parameters {
choice(choices: ['yes' , 'no'], name: 'HALT', description: '')
}
}
steps {
script {
if (env.HALT=='yes') {
sh "curl -s -X DELETE https://api.gremlin.com/v1/attacks/${ATTACK_ID} -H 'X-Gremlin-Agent: jenkins' -H 'Authorization: Key ${GREMLIN_API_KEY}' --compressed"
}
}
}
}
}
}
Staging Chaos Pipeline

Conclusion

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Moving forward with Kotlin #1: Properties

How I passed the AWS Certified Solutions Architect Associate Exam (SAA-CO2)

Blunder | HackTheBox

The Value of Tracking Time Spent on GitLab Issues

Types of Tasks for a Virtual Assistant (with Examples)

Increase Hadoop Distributed Storage Dynamically

Adapting to Disruptive Technology

Today is the day when I finished 50 problems from LeetCode.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tammy Bryant Butow

Tammy Bryant Butow

More from Medium

Noobs Guide for your first DevOps CI/CD project

Installing Jenkins on CentOS

Build a Docker Jenkins Pipeline to Implement CI/CD Workflow