forked from crossplane/crossplane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
151 lines (139 loc) · 5.2 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
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
pipeline {
agent { label 'upbound-gce' }
parameters {
booleanParam(defaultValue: true, description: 'Execute pipeline?', name: 'shouldBuild')
}
options {
disableConcurrentBuilds()
timestamps()
timeout(time: 30, unit: 'MINUTES')
}
environment {
RUNNING_IN_CI = 'true'
REPOSITORY_NAME = "${env.GIT_URL.tokenize('/')[3].split('\\.')[0]}"
REPOSITORY_OWNER = "${env.GIT_URL.tokenize('/')[2]}"
DOCKER = credentials('dockerhub-upboundci')
AWS = credentials('aws-upbound-bot')
GITHUB_UPBOUND_BOT = credentials('github-upbound-jenkins')
CODECOV_TOKEN = credentials('codecov-crossplane')
}
stages {
stage('Prepare') {
steps {
script {
if (env.CHANGE_ID != null) {
def json = sh (script: "curl -s https://api.github.com/repos/crossplane/crossplane/pulls/${env.CHANGE_ID}", returnStdout: true).trim()
def body = evaluateJson(json,'${json.body}')
if (body.contains("[skip ci]")) {
echo ("'[skip ci]' spotted in PR body text.")
env.shouldBuild = "false"
}
}
}
sh 'git config --global user.name "upbound-bot"'
sh 'echo "machine github.com login upbound-bot password $GITHUB_UPBOUND_BOT" > ~/.netrc'
}
}
stage('Build'){
when {
expression {
return env.shouldBuild != "false"
}
}
steps {
sh './build/run make check-diff'
sh './build/run make vendor.check'
sh './build/run make -j\$(nproc) build.all'
}
}
stage('Unit Tests') {
when {
expression {
return env.shouldBuild != "false"
}
}
steps {
sh './build/run make -j\$(nproc) test'
sh './build/run make -j\$(nproc) cobertura'
}
post {
always {
archiveArtifacts "_output/tests/**/*"
junit "_output/tests/**/unit-tests.xml"
cobertura coberturaReportFile: '_output/tests/**/cobertura-coverage.xml',
classCoverageTargets: '50, 0, 0',
conditionalCoverageTargets: '70, 0, 0',
lineCoverageTargets: '40, 0, 0',
methodCoverageTargets: '30, 0, 0',
packageCoverageTargets: '80, 0, 0',
autoUpdateHealth: false,
autoUpdateStability: false,
enableNewApi: false,
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: false
}
}
}
stage("Integration Tests"){
when {
expression {
return env.shouldBuild != "false"
}
}
steps {
sh './build/run make -j\$(nproc) e2e'
}
}
stage('Publish Coverage to Codecov') {
when {
expression {
return env.shouldBuild != "false"
}
}
steps {
script {
sh 'curl -s https://codecov.io/bash | bash -s -- -c -f _output/tests/**/coverage.txt -F unittests'
}
}
}
stage('Publish') {
when {
expression {
return env.shouldBuild != "false"
}
}
steps {
sh 'docker login -u="${DOCKER_USR}" -p="${DOCKER_PSW}"'
sh "./build/run make -j\$(nproc) publish BRANCH_NAME=${BRANCH_NAME} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} GIT_API_TOKEN=${GITHUB_UPBOUND_BOT}"
script {
if (BRANCH_NAME == 'master') {
lock('promote-job') {
sh "./build/run make -j\$(nproc) promote BRANCH_NAME=master CHANNEL=master AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW}"
}
}
}
}
}
}
post {
always {
script {
sh 'make -j\$(nproc) clean'
sh 'make -j\$(nproc) prune PRUNE_HOURS=48 PRUNE_KEEP=48'
sh 'docker images'
deleteDir()
}
}
}
}
@NonCPS
def evaluateJson(String json, String gpath){
//parse json
def ojson = new groovy.json.JsonSlurper().parseText(json)
//evaluate gpath as a gstring template where $json is a parsed json parameter
return new groovy.text.GStringTemplateEngine().createTemplate(gpath).make(json:ojson).toString()
}