-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile.ci
163 lines (136 loc) · 6.03 KB
/
Jenkinsfile.ci
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
@Library("stargazer-io@ssdc-pipe") _
def prescription
pipeline {
environment {
APP_NAME = 'expresscart'
TYPE = 'ssdc'
BASE_IMAGE = 'mhart/alpine-node:8'
BUILD_JOB = 'build-swag-store-nodejs-synopsys'
seekerProject = 'express_cart_ebc'
projectVersion = "SIG-1.6.13"
tinfoilProject = 'sig-employee-store-ssdc'
STARGAZER_URL = credentials('stargazer-url')
}
agent
{
node {
label 'linux'
customWorkspace "${env.JobPath}"
}
}
stages
{
stage('Start') {
steps {
echo 'start'
}
}
stage ('Build') {
steps {
script {
build job: env.BUILD_JOB, propagate: true, wait: true
}
}
}
stage ('Restore artifacts') {
steps {
script {
sh("curl -o artifacts.tgz http://nexus.nexus.svc:8081/repository/vebc/${env.APP_NAME}/artifacts/${env.TYPE}/artifacts-${env.TYPE}.tgz")
sh ("tar xfz artifacts.tgz && cp -f Dockerfile.test Dockerfile")
}
}
}
stage ('Load AST prescription') {
steps {
script {
prescription = unstashPrescription()
}
}
}
stage ('Create Image'){
steps {
script {
/* Handle updates to base image */
sh ( 'test -f ./jq || curl -o jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && chmod +x jq')
TARGET_BASE_IMAGE = sh ( script: "grep -Po \'^\\s*FROM\\s+\\K[^\\n]*\' ./Dockerfile", returnStdout: true).trim()
echo "Desired image: ${TARGET_BASE_IMAGE}"
CURRENT_BASE_IMAGE = ""
try {
CURRENT_BASE_IMAGE = sh ( script: "if oc describe bc/${env.APP_NAME}-${env.TYPE} > /dev/null ; then oc get buildconfig/${env.APP_NAME}-${env.TYPE} -o json | ./jq '.spec.strategy.dockerStrategy.from.name' | sed 's/\"//g'; else echo -n ''; fi", returnStdout: true).trim()
} catch (err) {
echo err.getMessage()
}
echo "Current image: $CURRENT_BASE_IMAGE"
if (CURRENT_BASE_IMAGE == "") {
BASE_IMAGE = TARGET_BASE_IMAGE
}
else {
size = TARGET_BASE_IMAGE.split('/').size()
echo "Size: $size"
if (size == 2) {
BASE_IMAGE = TARGET_BASE_IMAGE.split('/')[1]
if (BASE_IMAGE != CURRENT_BASE_IMAGE) {
sh ( script: "oc delete bc/${env.APP_NAME}-${env.TYPE};", returnStdout: true).trim()
}
} else {
BASE_IMAGE = CURRENT_BASE_IMAGE
}
}
echo "Configuring image: $BASE_IMAGE"
try {
sh "if oc describe bc/${env.APP_NAME}-${env.TYPE} > /dev/null ; then echo \"config exists\"; else oc new-build --strategy docker --binary --docker-image $BASE_IMAGE --name ${env.APP_NAME}-${env.TYPE}; fi"
} catch (err) {
// oc new-build will return an error if *any* of the dependencies already exist - so catch it and let the remainder fail which should prompt a look at hte logs
echo err.getMessage()
}
sh "oc start-build ${env.APP_NAME}-${env.TYPE} --from-dir ./ --follow"
}
}
}
stage ('Publish app'){
steps {
script {
sh "if oc describe dc/${env.APP_NAME}-${env.TYPE} > /dev/null; then echo \"deployment config exists\"; else oc new-app ${env.APP_NAME}-${env.TYPE}; oc expose svc/${env.APP_NAME}-${env.TYPE}; fi"
}
}
}
stage ('Enable Synopsys Seeker on App'){
steps {
script {
withCredentials([
string(credentialsId: 'testing-seeker-url', variable: 'SEEKERURL')
]){
sh "oc set env dc/${env.APP_NAME}-${env.TYPE} --overwrite SEEKER_SERVER_URL=\"$SEEKERURL\""
}
sh "oc set env dc/${env.APP_NAME}-${env.TYPE} --overwrite SEEKER_PROJECT_KEY=\"${env.seekerProject}\""
sh "oc set volume dc/${env.APP_NAME}-${env.TYPE} --add --overwrite --name=seeker-vol --path=/var/seeker --mount-path=/seeker"
sleep 15 /*wait for agent startup */
}
}
}
stage ('Trigger Synopsys Tinfoil Web Scan'){
when {
expression {
return shouldScan (prescription, "dast")
}
}
steps {
script {
withCredentials([
string(credentialsId: 'tinfoil-url', variable: 'TINFOILURL'),
string(credentialsId: 'tinfoil-token', variable: 'TOKEN'),
string(credentialsId: 'tinfoil-access-key', variable: 'ACCESS_KEY')
]){
sh "curl $TINFOILURL/api/v1/sites/${env.tinfoilProject}/scans -d '' -H 'Authorization:Token token=$TOKEN, access_key=$ACCESS_KEY'"
}
prescription = completedScan (prescription, "dast")
}
}
}
stage('End') {
steps {
echo 'end'
}
}
}
}