forked from navikt/aksel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
153 lines (134 loc) · 4.42 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
152
153
#!groovy
@Library('common')
import common
def common = new common()
moduleUrl = 'http://cisbl.devillo.no:8000'
moduleChannel = 'natthauk-ops'
application = "nav-frontend-moduler"
releaseVersion = "Unknown"
isMasterBuild = (env.BRANCH_NAME == 'master')
lastcommit = "Unknown"
committerEmail = "Unknown"
def notifyFailed(reason, error) {
chatmsg = "**[${application} ${releaseVersion}](${moduleUrl}) ${reason} **\n\n${lastcommit} (${committerEmail})"
mattermostSend channel: moduleChannel, color: 'danger', message: chatmsg
currentBuild.result = 'FAILED'
step([$class: 'StashNotifier'])
throw error
}
def returnOk(message) {
echo "${message}"
currentBuild.result = "SUCCESS"
step([$class: 'StashNotifier'])
}
node('master') {
common.setupTools("Maven 3.3.3", "java8")
stage('Checkout') {
deleteDir()
checkout scm
step([$class: 'StashNotifier'])
committerEmail = sh(script: 'git log -1 --pretty=format:"%ae"', returnStdout: true).trim()
lastcommit = sh(script: 'git log -1 --pretty=format:"%ae (%an) %h %s" --no-merges', returnStdout: true).trim()
pom = readMavenPom file: 'app-config/pom.xml'
releaseVersion = "${pom.version}.${currentBuild.number}"
}
if (!isMasterBuild) {
stage('Merge master') {
sh "git merge origin/master"
}
}
stage('Install') {
try {
sh "npm run installAfterConfig"
} catch(Exception e) {
notifyFailed("Bygg feilet ved npm-install", e)
}
}
stage('Lint') {
try {
sh "npm run lint"
} catch(Exception e) {
notifyFailed("Linting feilet", e)
}
}
stage('Test') {
try {
sh "npm run checkversions"
} catch(Exception e) {
notifyFailed("Versjonssjekker feilet", e)
}
try {
sh "npm test"
} catch(Exception e) {
notifyFailed("Tester feilet", e)
}
}
stage('Build') {
try {
sh "npm run build"
} catch(Exception e) {
notifyFailed("Bygging av JS feilet", e)
}
}
if (!isMasterBuild) {
returnOk("This is enough for now. I'm not releasing anything before it is on the master-branch....")
return
}
hasPublished = true
stage('Publish modules') {
try {
sh "npm run CI:lerna:publish"
currentBuild.description = sh(script: 'git tag --points-at HEAD', returnStdout: true).trim() ?: ''
// sh "mvn versions:set -f app-config/pom.xml -DgenerateBackupPoms=false -B -DnewVersion=${releaseVersion}"
} catch (ignored) {
hasPublished = false
currentBuild.description = "Ingen nye moduler"
}
}
if (!hasPublished) {
returnOk("No need to continue as no modules were published...")
return
}
stage('Build storybook') {
try {
sh "npm run buildstorybook"
} catch(Exception e) {
notifyFailed("Bygging av storybook feilet", e)
}
}
stage('Dockerify') {
script {
try {
GString imageName = "docker.adeo.no:5000/${application}:${releaseVersion}"
sh "git push origin master"
sh "git push --tags"
// sh "docker build -t ${imageName} ."
// sh "docker push ${imageName}"
// sh "mvn clean deploy -f app-config/pom.xml -DskipTests -B -e"
} catch(Exception e) {
notifyFailed("Pushing til git og dockerify", e)
}
}
}
}
//stage("Deploy app") {
// callback = "${env.BUILD_URL}input/Deploy/"
// node {
// def author = sh(returnStdout: true, script: 'git --no-pager show -s --format="%an <%ae>" HEAD').trim()
// def deploy = common.deployApp(application, releaseVersion, miljo, callback, author).key
//
// try {
// timeout(time: 15, unit: 'MINUTES') {
// input id: 'deploy', message: "deployer ${deploy}, deploy OK?"
// }
// } catch(Exception e) {
// msg = "Deploy feilet [" + deploy + "](https://jira.adeo.no/browse/" + deploy + ")"
// notifyFailed(msg, e)
// }
// }
//}
chatmsg = "**[${application}](${moduleUrl}) Bygg OK**\n\n${lastcommit} (${committerEmail}"
mattermostSend channel: moduleChannel, color: 'good', message: chatmsg
node {
returnOk('All good')
}