forked from crossplane/crossplane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
102 lines (93 loc) · 3.38 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
pipeline {
agent { label 'upbound-gce' }
options {
disableConcurrentBuilds()
timestamps()
}
environment {
DOCKER = credentials('dockerhub-upboundci')
AWS = credentials('aws-upbound-bot')
GITHUB_UPBOUND_BOT = credentials('github-upbound-jenkins')
}
stages {
stage('Prepare') {
steps {
script {
if (env.BRANCH_NAME =~ /^PR-\d+$/) {
def pr_number = sh (script: "echo ${env.BRANCH_NAME} | grep -o -E '[0-9]+' ", returnStdout: true)
def json = sh (script: 'curl -s -H "Authorization: token ${GITHUB_UPBOUND_BOT}" https://api.github.com/repos/crossplaneio/crossplane/pulls/${pr_number}', 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 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'
}
post {
always {
archiveArtifacts "_output/tests/**/*"
junit "_output/tests/**/*.xml"
}
}
}
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()
}