This repository has been archived by the owner on Jan 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
69 lines (60 loc) · 2.56 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
#!groovy
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')),
disableConcurrentBuilds()
])
final String BRANCH = env.BRANCH_NAME
node('') {
def nodeHome = tool name: 'node', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
def customEnv = [
"PATH+NODE=${nodeHome}/bin"
]
step([$class: 'WsCleanup'])
try {
withEnv(customEnv) {
stage('Checkout SCM') {
echo "Running for branch ${BRANCH}"
checkout scm
def GIT_COMMIT_AUTHOR = sh(returnStdout: true, script: 'git --no-pager show -s --format="%an"').trim()
env.GIT_COMMIT_AUTHOR = "${GIT_COMMIT_AUTHOR}"
env.GIT_COMMIT = '' + sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
}
if (env.GIT_COMMIT_AUTHOR == 'LHT jenkins LHT.build (tiebs)') {
echo "Last change was commit by Jenkins (${env.GIT_COMMIT_AUTHOR}), exiting to prevent infinite loop."
currentBuild.result = 'SUCCESS'
return
}
stage('Build App') {
sh "npm install"
sh "npm run build"
}
stage('Publish') {
configFileProvider([configFile(fileId: 'npm_publish_settings', targetLocation: '.npmrc')]) {
if (BRANCH == 'master') {
def version = shWithResult("node -p -e \"require('./package.json').version\"")
currentBuild.displayName = version
sshagent(credentials: ['community_write'], ignoreMissing: true) {
sh("npm publish dist && git push --tags origin HEAD:" + BRANCH)
}
}
}
}
}
} catch (final e) {
mailNotification()
throw e
} finally {
echo "finished"
}
}
def mailNotification() {
final def buildStatus = "FAILURE"
if (buildStatus != "SUCCESS") {
stage('Mail Notification') {
echo "Notifying culprits of build ${buildStatus.toLowerCase()}"
final String subject = "${buildStatus}: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}]"
final String details = "${subject}:\nCheck console output at ${env.BUILD_URL}"
emailext attachLog: true, subject: "[JENKINS] ${subject}", body: details, recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider']]
}
}
}