forked from Contrast-Security-OSS/demo-netflicks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
83 lines (81 loc) · 3.03 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
env.terraform_version = '0.12.3'
pipeline {
agent any
stages {
stage('dependencies') {
steps {
sh """
FILE=/usr/bin/terraform
if [ -f "\$FILE" ]; then
echo "\$FILE exists, skipping download"
else
echo "\$FILE does not exist"
cd /tmp
curl -o terraform.zip https://releases.hashicorp.com/terraform/'$terraform_version'/terraform_'$terraform_version'_linux_amd64.zip
unzip -o terraform.zip
sudo mv terraform /usr/bin
rm -rf terraform.zip
fi
"""
script {
withCredentials([file(credentialsId: env.contrast_yaml, variable: 'path')]) {
def contents = readFile(env.path)
writeFile file: 'contrast_security.yaml', text: "$contents"
}
}
sh """
terraform init
npm i puppeteer
"""
}
}
stage('provision') {
steps {
script {
withCredentials([azureServicePrincipal('ContrastAzureSponsored')]) {
try {
sh """
export ARM_CLIENT_ID=$AZURE_CLIENT_ID
export ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET
export ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID
export ARM_TENANT_ID=$AZURE_TENANT_ID
terraform apply -auto-approve -var 'location=$location' -var 'initials=$initials' -var 'environment=qa' -var 'servername=jenkins'
"""
} catch (Exception e) {
echo "Terraform refresh failed, deleting state"
sh "rm -rf terraform.tfstate"
currentBuild.result = "FAILURE"
error("Aborting the build.")
}
}
}
}
}
stage('sleeping') {
steps {
sleep 120
}
}
stage('exercise') {
steps {
timeout(20) {
sh """
FQDN=\$(terraform output fqdn)
BASEURL=\$FQDN node exercise.js
"""
}
}
}
stage('destroy') {
steps {
withCredentials([azureServicePrincipal('ContrastAzureSponsored')]) {
sh """export ARM_CLIENT_ID=$AZURE_CLIENT_ID
export ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET
export ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID
export ARM_TENANT_ID=$AZURE_TENANT_ID
terraform destroy -auto-approve"""
}
}
}
}
}