-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfileRelease
109 lines (91 loc) · 2.7 KB
/
JenkinsfileRelease
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
pipeline {
tools {
nodejs 'nodejs-20.11.1'
}
parameters {
gitParameter name: 'branch',
description: 'The branch to check out',
branchFilter: 'origin/(.*)',
defaultValue: 'main',
selectedValue: 'DEFAULT',
type: 'PT_BRANCH',
listSize: '0',
quickFilterEnabled: true
string name: 'ReleaseVersion',
description: 'Version to release',
defaultValue: ''
}
agent {
label 'graphdb-jenkins-node-2'
}
options {
disableConcurrentBuilds()
timeout(time: 15, unit: 'MINUTES')
timestamps()
}
environment {
CI = "true"
NPM_TOKEN = credentials('npm-token')
COMPOSE_PROJECT_NAME = "${JOB_NAME}_${BUILD_NUMBER}"
}
stages {
stage('Log Info') {
steps {
echo "Job name: ${JOB_NAME}"
echo "Build no.: ${BUILD_NUMBER}"
}
}
stage ('Prepare') {
steps {
// Switch to branch
sh "git checkout ${branch}"
// Change versions
dir("ontotext-graphql-playground-component/") {
sh "npm version --git-tag-version=false ${ReleaseVersion}"
}
// Export COMPOSE_PROJECT_NAME for use in docker-compose
sh "export COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}"
// Install & Build graphiql
sh 'docker-compose -p ${COMPOSE_PROJECT_NAME} up --build --abort-on-container-exit'
// Install & Build component
sh 'npm run install:component:ci'
sh 'npm run build:component'
// Align folder permissions
sh 'sudo chown -R \$(id -u):\$(id -g) .'
}
}
stage ('Publish') {
steps {
// Publish on npm
dir("ontotext-graphql-playground-component/") {
sh "echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc && npm publish"
}
}
}
}
post {
always {
sh "docker-compose -p ${env.COMPOSE_PROJECT_NAME} down --remove-orphans --rmi all || true"
dir("ontotext-graphql-playground-component/") {
sh "rm .npmrc"
}
}
success {
// Commit, tag and push the changes in Git
sh "git commit -a -m 'Release ${ReleaseVersion}'"
sh "git tag -a v${ReleaseVersion} -m 'Release v${ReleaseVersion}'"
sh "git push --set-upstream origin ${branch} && git push --tags"
}
failure {
wrap([$class: 'BuildUser']) {
emailext(
to: env.BUILD_USER_EMAIL,
from: "Jenkins <[email protected]>",
subject: '''[Jenkins] $PROJECT_NAME - Build #$BUILD_NUMBER - $BUILD_STATUS!''',
mimeType: 'text/html',
body: '''${SCRIPT, template="groovy-html.template"}'''
)
}
}
}
}