-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
94 lines (84 loc) · 2.87 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
@Library('jenkins.shared.library') _
pipeline {
agent {
label 'ubuntu_docker_label'
}
tools {
go "Go 1.14.4"
}
environment {
PROJECT = "src/github.com/xdu31/exercise-service"
GOPATH = "$WORKSPACE"
PATH = "$PATH:$GOPATH/bin"
image_repo = "xdu31/exercise-service"
upstream_github_repo = "xdu31/exercise-service"
upstream_execution_url = "$BUILD_URL"
upstream_job_name = "$JOB_BASE_NAME"
upstream_build_id = "$BUILD_ID"
email_recipients = "eaglerose31@gmail.com"
GIT_BRANCH = rewrite_image_tag(env.GIT_BRANCH)
}
options {
checkoutToSubdirectory("src/github.com/xdu31/exercise-service")
}
stages {
stage('Build image') {
steps {
sh "cd $PROJECT && make GO_CACHE= build && make image"
}
}
stage("Check pull request") {
when {
expression {
return env.BRANCH_NAME.startsWith('PR')
}
}
steps {
sh """
sudo curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
cd $PROJECT && make itest
"""
}
}
stage("Push chart") {
when {
expression { !isPrBuild() }
}
steps {
withAWS(region:'us-east-1', credentials:'CICD_HELM') {
sh "cd $PROJECT && make push-chart"
}
dir("${WORKSPACE}/${PROJECT}") {
archiveArtifacts artifacts: 'helm/*.tgz'
archiveArtifacts artifacts: 'helm/build.properties'
}
}
}
stage("Cleaning") {
steps {
sh "cd $PROJECT && make clean"
}
}
}
post {
success {
echo 'calling CVE scanning job now . . .'
build job: 'run_docker_image_cve_scan',
parameters: [
string(name: 'repo', value: env.image_repo),
string(name: 'upstream_github_repo', value: env.upstream_github_repo),
string(name: 'upstream_execution_url', value: env.upstream_execution_url),
string(name: 'upstream_job_name', value: env.upstream_job_name),
string(name: 'upstream_build_id', value: env.upstream_build_id),
string(name: 'email_recipients', value: env.email_recipients)
],
wait: false
}
}
}
def rewrite_image_tag(tag){
tag=tag.replace("/", "-")
return tag
}