-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
134 lines (101 loc) · 3.9 KB
/
Jenkinsfile
File metadata and controls
134 lines (101 loc) · 3.9 KB
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
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '3'))
}
stages {
stage("Notify Job Start"){
environment {
GIT_LOG = sh(script: 'git log --pretty=format:"%cn : %s" ${GIT_PREVIOUS_SUCCESSFUL_COMMIT}..HEAD', , returnStdout: true).trim()
}
steps {
slackNotification('STARTED_JOB : '+ JOB_NAME +" "+JOB_URL)
slackNotification('COMMIT_LIST : \n'+ env.GIT_LOG)
}
}
stage('Build App & Container Image') {
steps{
sh 'npm install'
sh 'npm run build'
sh 'docker build -t liveui/liveui-website:latest .'
}
}
stage ('NPM Scan') {
steps {
sh 'npm run generate-audit-report'
}
post {
always {
archiveArtifacts artifacts: 'npm-report.html', fingerprint: true
}
}
}
stage('Image Scan') {
agent {
docker {
image 'aquasec/trivy'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock -v trivy_cache:/cache --entrypoint= '
}
}
steps {
sh 'trivy --cache-dir /cache -f json -o trivy-results.json liveui/liveui-website'
sh 'cat trivy-results.json'
}
post {
always {
archiveArtifacts artifacts: 'trivy-results.json', fingerprint: true
}
}
}
stage('Login GCR') {
steps{
withCredentials([string(credentialsId: 'eteration-gcr-docker-login-key', variable: 'GCR_IO_CREDENTIALS')]) {
sh 'docker login -u _json_key -p "${GCR_IO_CREDENTIALS}" https://gcr.io'
}
}
}
stage ('Image Push') {
steps {
sh 'docker tag liveui/liveui-website:latest gcr.io/eteration/liveui/liveui-website:latest'
sh 'docker push gcr.io/eteration/liveui/liveui-website:latest'
}
}
stage('Deploy') {
agent {
docker {
image 'gcr.io/eteration/cnf/kubectl-runner:latest'
args '-t'
}
}
steps {
withKubeConfig([credentialsId: 'common-west.k8s.eteration.com',
serverUrl: 'https://api.common-west.k8s.eteration.com',
clusterName: 'common-west.k8s.eteration.com',
namespace: 'liveui'
]) {
sh "kubectl apply -f ./platform/k8s/"
sh './patch.sh'
}
}
}
}
post{
always {
echo "Pipeline result: ${currentBuild.result}"
script {
slackNotification("FINISHED_JOB : "+env.JOB_NAME +" :"+ currentBuild.result + " "+ JOB_DISPlAY_URL )
}
}
}
}
def slackNotification(String msg) {
withCredentials([string(credentialsId: 'slack_token', variable: 'slack_token')]) {
def payload = groovy.json.JsonOutput.toJson([
text: msg,
channel: "#secops",
username: "jenkins",
icon_emoji:":bowtie:"
])
sh "curl -X POST -H 'Content-type: application/json' --data \'${payload}\' https://hooks.slack.com/services/T223TGSTS/${slack_token}"
}
}