forked from y-kkamil/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
111 lines (95 loc) · 4.58 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
#!/usr/bin/env groovy
def label = "kyma-${UUID.randomUUID().toString()}"
def application = 'console'
def isMaster = params.GIT_BRANCH == 'master'
def dockerPushRoot = isMaster
? "${env.DOCKER_REGISTRY}"
: "${env.DOCKER_REGISTRY}snapshot/"
def dockerImageTag = isMaster
? params.APP_VERSION
: params.GIT_BRANCH
echo """
********************************
Job started with the following parameters:
DOCKER_REGISTRY=${env.DOCKER_REGISTRY}
DOCKER_CREDENTIALS=${env.DOCKER_CREDENTIALS}
CHECKMARX_LIBRARY=${env.CHECKMARX_LIBRARY}
GIT_REVISION=${params.GIT_REVISION}
GIT_BRANCH=${params.GIT_BRANCH}
APP_VERSION=${params.APP_VERSION}
APP_FOLDER=${env.APP_FOLDER}
********************************
"""
podTemplate(label: label) {
node(label) {
try {
timestamps {
timeout(time:20, unit:"MINUTES") {
ansiColor('xterm') {
stage("setup") {
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"
}
// if (isMaster) {
// ws() {
// scriptUrl = "$env.CHECKMARX_LIBRARY"
// scan = loadModule url: scriptUrl, name: 'scan', branch: 'kyma'
// }
// }
}
stage("resolve dependencies $application") {
execute("npm install -f")
}
stage("code quality $application") {
execute("make validate")
}
stage("test $application") {
execute("npm run test:single")
}
if (isMaster) {
stage("IP scan $application (WhiteSource)") {
withCredentials([string(credentialsId: 'whitesource_apikey', variable: 'apikey'), string(credentialsId: 'whitesource_userkey', variable: 'userkey')]) {
execute("make scan", ["API_KEY=$apikey", "USER_KEY=$userkey"])
}
}
// stage("security scan $application (Checkmarx)"){
// scan.checkmarx(projectname: "KYMA_" + application.toUpperCase() + "_" + "MASTER", credentialsId: 'checkmarx' )
// }
}
stage("build $application") {
execute('make build')
}
stage("build image $application") {
dir(env.APP_FOLDER){
sh "docker build . -t $application:latest"
}
}
stage("push image $application") {
sh "docker tag ${application}:latest ${dockerPushRoot}${application}:${dockerImageTag}"
sh "docker push ${dockerPushRoot}${application}:${dockerImageTag}"
}
}
}
}
} catch (ex) {
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, envs = []) {
def repositoryName = 'console'
def buildpack = 'node-buildpack:0.0.10'
def envText = ''
for (it in envs) {
envText = "$envText --env $it"
}
workDir = pwd()
sh "docker run --rm -v $workDir:/$repositoryName -w /$repositoryName/$env.APP_FOLDER $envText ${env.DOCKER_REGISTRY}$buildpack /bin/bash -c '$command'"
}