This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
76 lines (65 loc) · 2.32 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
#!/usr/bin/env groovy
pipeline {
agent {label 'nodejs'}
stages {
stage('Build') {
steps {
echo '\nBuilding...'
setBuildStatus('Building...', 'PENDING')
// Install dependencies.
sh 'npm install'
// Disable git hooks in Jenkins, as they interfere with semantic-release.
sh 'rm -rf .git/hooks'
}
}
stage('Test') {
steps {
echo '\nTesting...'
setBuildStatus('Testing...', 'PENDING')
// Run the test suite.
sh 'npm test'
}
}
stage('Release') {
when {
branch 'master'
}
steps {
echo '\nBuilding...'
setBuildStatus('Publishing...', 'PENDING')
// Run semantic-release with the necessary credentials.
script {
credentials = [
string(credentialsId: 'github-personal-access-token', variable: 'GITHUB_TOKEN'),
string(credentialsId: 'npm-token', variable: 'NPM_TOKEN')
]
}
withCredentials(credentials) {
sh 'npx semantic-release'
}
// Update the build information with the appropriate metadata.
echo '\nFinishing up...'
script {
RELEASE_VERSION = sh ( script: "git tag --points-at HEAD", returnStdout: true ).trim()
if (RELEASE_VERSION) {
RELEASE_URL = "https://github.com/Tanndev/performance-profiler/releases/tag/${RELEASE_VERSION}"
echo "Version: ${RELEASE_VERSION} can be viewed at ${RELEASE_URL}"
currentBuild.displayName = RELEASE_VERSION
currentBuild.description = RELEASE_URL
}
}
}
}
}
post {
success {
setBuildStatus("Passed", "SUCCESS")
}
failure {
setBuildStatus( "Failed", "FAILED")
}
}
}
void setBuildStatus(String message, String status) {
githubNotify context: 'Jenkins CI', description: message, status: status
}