-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathJenkinsfile
125 lines (101 loc) · 3.35 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
@Library('GlobalJenkinsLibrary@2.0') _
env.NODE_VERSION = '8 --lts'
env.SLACK_TEAM = 'adidas-npm'
env.SLACK_CHANNEL = 'jenkins'
env.SLACK_CREDENTIALS = 'npm-slack-token'
// project config
def projectName
def version
def repo
// docker config
def dockerRepo = 'tools.adidas-group.com:5000'
def dockerPrefix = 'pabb'
def dockerCredentials = 'docker-automation'
// k8s config
def k8sCluster = 'k8s-on-prem-dev-agp'
def k8sNamespace = 'adidas-github-portal'
def dns = 'dev.github.adidas.com'
node {
meta.pipelines.withDefaults()
notifications.slack.send message: 'Started'
try {
stage('Collect info') {
checkout scm
projectName = tools.npm.getConfig 'name'
version = tools.npm.getConfig 'version'
repo = tools.git.getOriginUrl()
}
stage('Setup') {
tools.npm.setupPrivateRegistry()
tools.npm.withNvm {
sh 'npm install'
}
}
stage('Build') {
tools.npm.withNvm {
sh 'npm run lint'
withEnv([
'API_HOST=https://dev.api.adidas.com/github',
'API_KEY=fkmswmh44ngwr6r7hsjau4tm'
]) {
sh 'npm run build'
}
}
}
stage('Test') {
tools.npm.withNvm {
sh 'npm run test'
tools.sonar.run branch: env.BRANCH_NAME, version: version
}
}
if (env.BRANCH_NAME == 'develop') {
stage('Publish') {
sh 'rm -rf node_modules'
flows.docker.publish(
repo: dockerRepo,
image: "${dockerPrefix}/${projectName}",
tags: ['dev'],
credentials: dockerCredentials
)
notifications.slack.send message: 'Published'
}
stage('Deploy') {
def date = new Date()
withCredentials([
file(credentialsId: k8sCluster, variable: 'KUBECONFIG'),
]) {
withEnv([
"LAST_BUILD_DATE=${date}",
"NAMESPACE=${k8sNamespace}",
"DNS=${dns}",
"TAG=dev"
]) {
sh 'envsubst < ./deploy/all.yml > ./deploy.yml'
sh "kubectl --kubeconfig=${env.KUBECONFIG} apply -f deploy.yml"
}
}
notifications.slack.send message: 'Deployed'
}
stage('Build Prod') {
tools.npm.withNvm {
sh 'npm install'
sh 'npm run build'
}
}
stage('Publish Prod') {
sh 'rm -rf node_modules'
flows.docker.publish(
repo: dockerRepo,
image: "${dockerPrefix}/${projectName}",
tags: ['prod'],
credentials: dockerCredentials
)
notifications.slack.send message: 'Published prod'
}
}
notifications.slack.send message: 'Success'
} catch (def e) {
currentBuild.result = 'FAILURE'
notifications.slack.send message: e.message, level: 'error'
}
}