1+ properties([
2+ gitLabConnection('gitlab')
3+ ])
4+
15node('words-linux') {
26 try {
3- stage('checkout'){
4- checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-node.git']]])
5-
6- sh "git config user.email \"
[email protected] \""
7- sh "git config user.name \"jenkins\""
7+ gitlabCommitStatus("checkout") {
8+ stage('checkout'){
9+ checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-node.git']]])
810
9- withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', usernameVariable: 'gitUsername', passwordVariable: 'gitPass')]) {
10- gitRepoUrl = "https://${gitUsername}:${gitPass}@git.auckland.dynabic.com/words-cloud/words-cloud-node.git"
11- }
12- }
11+ sh "git config user.email \"
[email protected] \""
12+ sh "git config user.name \"jenkins\""
13+
14+ withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', usernameVariable: 'gitUsername', passwordVariable: 'gitPass')]) {
15+ gitRepoUrl = "https://${gitUsername}:${gitPass}@git.auckland.dynabic.com/words-cloud/words-cloud-node.git"
16+ }
17+ }
18+ }
1319
14- docker.image('node:latest').inside{
15- stage('build package'){
16- withEnv([
17- /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
18- 'npm_config_cache=npm-cache',
19- /* set home to our current directory because other bower
20- * nonsense breaks with HOME=/, e.g.:
21- * EACCES: permission denied, mkdir '/.config'
22- */
23- 'HOME=.',
24- ]) {
25- sh "npm install"
26- sh "npm run gulp buildRelease"
27- packageName = sh(returnStdout: true, script: 'npm pack').trim()
28-
29- }
30-
31- stash name: "newPackage", includes: "${packageName}"
32- }
20+ docker.image('node:latest').inside{
21+ gitlabCommitStatus("build package") {
22+ stage('build package'){
23+ withEnv([
24+ /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
25+ 'npm_config_cache=npm-cache',
26+ /* set home to our current directory because other bower
27+ * nonsense breaks with HOME=/, e.g.:
28+ * EACCES: permission denied, mkdir '/.config'
29+ */
30+ 'HOME=.',
31+ ]) {
32+ sh "npm install"
33+ sh "npm run gulp buildRelease"
34+ packageName = sh(returnStdout: true, script: 'npm pack').trim()
35+
36+ }
37+
38+ stash name: "newPackage", includes: "${packageName}"
39+ }
40+ }
3341 }
3442
35- stage('Merge master to testPackage'){
36- sh "git checkout --merge testPackage"
37- sh "git reset --hard origin/testPackage"
38- sh "git merge --no-ff --allow-unrelated-histories origin/master"
39- sh "git diff --name-status"
40- sh 'git commit -am "Merged master branch to testPackage" || exit 0'
41- sh "git push ${gitRepoUrl} testPackage"
42- }
43+ gitlabCommitStatus("Merge master to testPackage") {
44+ stage('Merge master to testPackage'){
45+ sh "git checkout --merge testPackage"
46+ sh "git reset --hard origin/testPackage"
47+ sh "git merge --no-ff --allow-unrelated-histories origin/master"
48+ sh "git diff --name-status"
49+ sh 'git commit -am "Merged master branch to testPackage" || exit 0'
50+ sh "git push ${gitRepoUrl} testPackage"
51+ }
52+ }
4353
44- stage('add reference to new package'){
45- unstash 'newPackage'
46- docker.image('node:latest').inside{
47- withEnv([
48- /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
49- 'npm_config_cache=npm-cache',
50- /* set home to our current directory because other bower
51- * nonsense breaks with HOME=/, e.g.:
52- * EACCES: permission denied, mkdir '/.config'
53- */
54- 'HOME=.',
55- ]) {
56- sh "npm uninstall asposewordscloud"
57- sh "npm install ${packageName}"
58- }
59- }
60-
61- sh "git diff --name-status"
62- sh "git ls-files --others --exclude-standard"
63- sh "git add -A"
64- sh 'git commit -am "new version of package added to repository" || exit 0'
65- sh "git push ${gitRepoUrl} testPackage"
66- }
54+ gitlabCommitStatus("Merge master to testPackage") {
55+ stage('add reference to new package'){
56+ unstash 'newPackage'
57+ docker.image('node:latest').inside{
58+ withEnv([
59+ /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
60+ 'npm_config_cache=npm-cache',
61+ /* set home to our current directory because other bower
62+ * nonsense breaks with HOME=/, e.g.:
63+ * EACCES: permission denied, mkdir '/.config'
64+ */
65+ 'HOME=.',
66+ ]) {
67+ sh "npm uninstall asposewordscloud"
68+ sh "npm install ${packageName}"
69+ }
70+ }
71+
72+ sh "git diff --name-status"
73+ sh "git ls-files --others --exclude-standard"
74+ sh "git add -A"
75+ sh 'git commit -am "new version of package added to repository" || exit 0'
76+ sh "git push ${gitRepoUrl} testPackage"
77+ }
78+ }
6779
6880 } finally {
6981 deleteDir()
82+ sh 'docker system prune -f'
7083 }
7184}
7285
@@ -85,69 +98,77 @@ stage('wait for publish confirmation'){
8598
8699node('words-linux') {
87100 try {
88- stage('checkout again'){
89- checkout([$class: 'GitSCM', branches: [[name: '*/testPackage']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-node.git']]])
90-
91- sh "git config user.email \"
[email protected] \""
92- sh "git config user.name \"jenkins\""
93-
94- withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', usernameVariable: 'gitUsername', passwordVariable: 'gitPass')]) {
95- gitRepoUrl = "https://${gitUsername}:${gitPass}@git.auckland.dynabic.com/words-cloud/words-cloud-node.git"
96- }
101+ gitlabCommitStatus("checkout again") {
102+ stage('checkout again'){
103+ checkout([$class: 'GitSCM', branches: [[name: '*/testPackage']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-node.git']]])
104+
105+ sh "git config user.email \"
[email protected] \""
106+ sh "git config user.name \"jenkins\""
107+
108+ withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', usernameVariable: 'gitUsername', passwordVariable: 'gitPass')]) {
109+ gitRepoUrl = "https://${gitUsername}:${gitPass}@git.auckland.dynabic.com/words-cloud/words-cloud-node.git"
110+ }
97111
98- sh "git checkout testPackage"
99- sh "git reset --hard origin/testPackage"
100- }
112+ sh "git checkout testPackage"
113+ sh "git reset --hard origin/testPackage"
114+ }
115+ }
101116
102- stage('publish package'){
103- docker.image('node:latest').inside{
104- withEnv([
105- /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
106- 'npm_config_cache=npm-cache',
107- /* set home to our current directory because other bower
108- * nonsense breaks with HOME=/, e.g.:
109- * EACCES: permission denied, mkdir '/.config'
110- */
111- 'HOME=.',
112- ]) {
113- withCredentials([string(credentialsId: '19f0eab9-c600-4746-a4bd-724efd2102c8', variable: 'npmToken')]) {
114- sh "echo //registry.npmjs.org/:_authToken=${npmToken} > .npmrc"
115- sh "npm publish ${packageName}"
116- }
117- }
118- }
117+ gitlabCommitStatus("publish package") {
118+ stage('publish package'){
119+ docker.image('node:latest').inside{
120+ withEnv([
121+ /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
122+ 'npm_config_cache=npm-cache',
123+ /* set home to our current directory because other bower
124+ * nonsense breaks with HOME=/, e.g.:
125+ * EACCES: permission denied, mkdir '/.config'
126+ */
127+ 'HOME=.',
128+ ]) {
129+ withCredentials([string(credentialsId: '19f0eab9-c600-4746-a4bd-724efd2102c8', variable: 'npmToken')]) {
130+ sh "echo //registry.npmjs.org/:_authToken=${npmToken} > .npmrc"
131+ sh "npm publish ${packageName}"
132+ }
133+ }
134+ }
135+ }
119136 }
120137
121- stage('change reference to published package'){
122- docker.image('node:latest').inside{
123- withEnv([
124- /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
125- 'npm_config_cache=npm-cache',
126- /* set home to our current directory because other bower
127- * nonsense breaks with HOME=/, e.g.:
128- * EACCES: permission denied, mkdir '/.config'
129- */
130- 'HOME=.',
131- ]) {
132- sh "npm uninstall asposewordscloud"
133- sh "npm install asposewordscloud"
134- }
135- }
138+ gitlabCommitStatus("change reference to published package") {
139+ stage('change reference to published package'){
140+ docker.image('node:latest').inside{
141+ withEnv([
142+ /* Override the npm cache directory to avoid: EACCES: permission denied, mkdir '/.npm' */
143+ 'npm_config_cache=npm-cache',
144+ /* set home to our current directory because other bower
145+ * nonsense breaks with HOME=/, e.g.:
146+ * EACCES: permission denied, mkdir '/.config'
147+ */
148+ 'HOME=.',
149+ ]) {
150+ sh "npm uninstall asposewordscloud"
151+ sh "npm install asposewordscloud"
152+ }
153+ }
136154
137- sh "git diff --name-status"
138- sh 'git commit -am "reference changed to published package" || exit 0'
139- sh "git push ${gitRepoUrl} testPackage"
155+ sh "git diff --name-status"
156+ sh 'git commit -am "reference changed to published package" || exit 0'
157+ sh "git push ${gitRepoUrl} testPackage"
158+ }
140159 }
141160
142- stage('add version tag') {
143- final fullVersion = packageName.substring(packageName.lastIndexOf('@') + 1, packageName.length())
144- final version = fullVersion.substring(0, fullVersion.lastIndexOf('.'))
161+ gitlabCommitStatus("add version tag") {
162+ stage('add version tag') {
163+ final fullVersion = packageName.substring(packageName.lastIndexOf('@') + 1, packageName.length())
164+ final version = fullVersion.substring(0, fullVersion.lastIndexOf('.'))
145165
146- sh "git tag -a ${version} -m \"version ${version}\""
147- sh "git push ${gitRepoUrl} ${version}"
166+ sh "git tag -a ${version} -m \"version ${version}\""
167+ sh "git push ${gitRepoUrl} ${version}"
168+ }
148169 }
149-
150170 } finally {
151171 deleteDir()
172+ sh 'docker system prune -f'
152173 }
153174}
0 commit comments