-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
112 lines (104 loc) · 3.51 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
#!/usr/bin/env groovy
def cleanup_workspace() {
cleanWs()
dir("${env.WORKSPACE}@tmp") {
deleteDir()
}
dir("${env.WORKSPACE}@script") {
deleteDir()
}
dir("${env.WORKSPACE}@script@tmp") {
deleteDir()
}
}
pipeline {
agent any
tools {
nodejs "node-lts"
}
environment {
NPM_RC_FILE = 'process-engine-ci-token'
NODE_JS_VERSION = 'node-lts'
}
stages {
stage('prepare') {
steps {
script {
raw_package_version = sh(script: 'node --print --eval "require(\'./package.json\').version"', returnStdout: true).trim()
package_version = raw_package_version.trim()
echo("Package version is '${package_version}'")
}
nodejs(configId: env.NPM_RC_FILE, nodeJSInstallationName: env.NODE_JS_VERSION) {
sh('node --version')
sh('npm install --ignore-scripts')
}
}
}
stage('build') {
steps {
sh('node --version')
sh('npm run build')
}
}
stage('publish') {
steps {
script {
def branch = env.BRANCH_NAME;
def branch_is_master = branch == 'master';
def new_commit = env.GIT_PREVIOUS_COMMIT != env.GIT_COMMIT;
if (branch_is_master) {
if (new_commit) {
script {
// let the build fail if the version does not match normal semver
def semver_matcher = package_version =~ /\d+\.\d+\.\d+/;
def is_version_not_semver = semver_matcher.matches() == false;
if (is_version_not_semver) {
error('Only non RC Versions are allowed in master')
}
}
def raw_package_name = sh(script: 'node --print --eval "require(\'./package.json\').name"', returnStdout: true).trim()
def current_published_version = sh(script: "npm show ${raw_package_name} version", returnStdout: true).trim();
def version_has_changed = current_published_version != raw_package_version;
if (version_has_changed) {
nodejs(configId: env.NPM_RC_FILE, nodeJSInstallationName: env.NODE_JS_VERSION) {
sh('node --version')
sh('npm publish --ignore-scripts')
}
} else {
println 'Skipping publish for this version. Version unchanged.'
}
}
} else {
// when not on master, publish a prerelease based on the package version, the
// current git commit and the build number.
// the published version gets tagged as the branch name.
def first_seven_digits_of_git_hash = env.GIT_COMMIT.substring(0, 8);
def publish_version = "${package_version}-${first_seven_digits_of_git_hash}-b${env.BUILD_NUMBER}";
def publish_tag = branch.replace("/", "~");
nodejs(configId: env.NPM_RC_FILE, nodeJSInstallationName: env.NODE_JS_VERSION) {
sh('node --version')
sh("npm version ${publish_version} --no-git-tag-version --force")
sh("npm publish --tag ${publish_tag} --ignore-scripts")
}
}
}
}
}
stage('cleanup') {
steps {
script {
// this stage just exists, so the cleanup-work that happens in the post-script
// will show up in its own stage in Blue Ocean
sh(script: ':', returnStdout: true);
}
}
}
}
post {
always {
script {
cleanup_workspace();
}
}
}
}