-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
103 lines (86 loc) · 3.66 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scmGit(branches: [[name: 'main']],
userRemoteConfigs: [[
url: '[email protected]:the-pod-shop/Pod-Shop-App-Configs.git',
credentialsId: 'git'
]])
}
}
stage('info') {
steps {
script {
sh'''
ls
'''
}
}
}
stage('Retrieve All Secrets') {
steps {
script {
export VAULT_ADDR='http://127.0.0.1:8200'
// Definieren der Vault-Endpunkt-URL
def vaultEndpoint = 'https://your-vault-server/v1/keyvalue'
// Laden der Liste der Secrets aus der Textdatei
def secretsText = readFile './terraform/secrets.txt'.trim()
// Durchlaufen der Liste und Abrufen jedes Secrets
secretsText.split('\n').each { line ->
def parts = line.split(/\s+/)
if (parts.size() == 2) {
def secretPath = parts[0]
def secretKey = parts[1]
// Abrufen des Geheimnisses aus Vault
def secretValue = sh(script: """
vault kv get -format=json '${vaultEndpoint}/${secretPath}' | jq -r '.data.data.${secretKey}'
""".trim(), returnStdout: true).trim()
echo "Retrieved '${secretKey}' from '${secretPath}': ${secretValue}"
}
}
}
}
}
stage('Analyze Terraform Plan with Checkov') {
steps {
script {
withCredentials([string(credentialsId: 'vault_token', variable: 'VAULT_TOKEN')]) {
sh '''
echo "--------remove old plan -------"
cd terraform # we need to cd to terraform in every stage
rm -f ./*.binary
rm -f ./*.xml
rm -f ./*.plan
rm -f ./*.json
ls -la
echo "--------start terraform plan -------"
terraform init -upgrade
terraform plan -var="vault_token=${VAULT_TOKEN}" --out tfplan.binary
terraform show -json tfplan.binary | jq > tfplan.json
ls -la
echo "-------- checkov scan -------"
checkov -f tfplan.json -o junitxml
chmod +x ./checkov_results.xml
ls -la
cat tfplan.json
cat ./checkov_results.xml
'''
}
}
}
}
}
post {
always {
withChecks(name: 'test', includeStage: true) {
junit 'checkov_results.xml'
}
}
}
}
options {
preserveStashes()
timestamps()
}