forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
107 lines (92 loc) · 4.04 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
#!/usr/bin/env groovy
def label = "kyma-${UUID.randomUUID().toString()}"
def application = 'ui-api-layer'
def dockerPushRoot = "${env.DOCKER_REGISTRY}${params.PUSH_DIR}"
def dockerImageTag = params.APP_VERSION
def registry = env.DOCKER_REGISTRY
def buildpack = 'golang-buildpack:0.0.9'
def appFolder = env.APP_FOLDER
def repositoryName = 'kyma'
def checkoutDir = "src/github.com/kyma-project/$repositoryName"
def componentDir = "$checkoutDir/$appFolder"
def workDir = ""
echo """
********************************
Job started with the following parameters:
DOCKER_REGISTRY=${env.DOCKER_REGISTRY}
PUSH_DIR=${params.PUSH_DIR}
DOCKER_CREDENTIALS=${env.DOCKER_CREDENTIALS}
GIT_REVISION=${params.GIT_REVISION}
GIT_BRANCH=${params.GIT_BRANCH}
APP_VERSION=${params.APP_VERSION}
APP_FOLDER=${env.APP_FOLDER}
FULL_BUILD=${params.FULL_BUILD}
********************************
"""
podTemplate(label: label,
containers: [
containerTemplate(name: "golang-buildpack", image: "${registry}${buildpack}", ttyEnabled: true, command: 'cat'),
]) {
node(label) {
try {
timestamps {
timeout(time:20, unit:"MINUTES") {
ansiColor('xterm') {
stage("setup") {
workDir = pwd()
dir(checkoutDir) {
checkout scm
}
if(dockerImageTag == ""){
error("No version for docker tag defined, please set APP_VERSION parameter for master branch or GIT_BRANCH parameter for any branch")
}
withCredentials([usernamePassword(credentialsId: env.DOCKER_CREDENTIALS, passwordVariable: 'pwd', usernameVariable: 'uname')]) {
sh "docker login -u $uname -p '$pwd' $env.DOCKER_REGISTRY"
}
}
stage("install dependencies $application") {
execute("dep ensure -v -vendor-only", workDir, componentDir)
}
stage("build and test $application") {
execute("./before-commit.sh ci", workDir, componentDir)
}
stage("build image $application") {
dir(componentDir) {
sh "docker build -t ${dockerPushRoot}${application}:latest . --label version=${dockerImageTag} --label component=${application}"
}
}
stage("push image $application") {
sh "docker tag ${dockerPushRoot}${application}:latest ${dockerPushRoot}${application}:${dockerImageTag}"
sh "docker push ${dockerPushRoot}${application}:${dockerImageTag}"
if (params.GIT_BRANCH == 'master') {
sh "docker push ${dockerPushRoot}${application}:latest"
}
}
}
}
}
} catch (ex) {
slaveDiagnostics()
execute("df -h", workDir, componentDir)
echo "Got exception: ${ex}"
currentBuild.result = "FAILURE"
def body = "${currentBuild.currentResult} ${env.JOB_NAME}${env.BUILD_DISPLAY_NAME}: on branch: ${params.GIT_BRANCH}. See details: ${env.BUILD_URL}"
emailext body: body, recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']], subject: "${currentBuild.currentResult}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
}
}
}
def execute(command, workDir, componentDir) {
container("golang-buildpack") {
sh """
export GOPATH=$workDir
cd $workDir/$componentDir
bash -c '$command'
"""
}
}
def slaveDiagnostics() {
sh "whoami"
sh "pwd"
sh "df -h"
sh "mount"
}