-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
137 lines (119 loc) · 4.34 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// TODO: Uncomment require line when Jenkins has been setup
// TODO: Setup environment config (npm and verdaccio)
// TODO: Configure remoteSsh function for correct ssh script to call
pipeline {
agent any
tools {
nodejs "latest"
}
environment {
NPM_CONFIG_ID = '7f444682-6d4a-4cba-b5d3-ed6c4bcdf4b2'
VERDACCIO_CONFIG_ID = '7dc1cf3e-46df-4208-b2e1-de2e83b9d9ae'
REGISTRY_DEV_HOST = "verdaccio.linto.ai"
PROD_HOST_NAME = 'stage.linto.ai'
DEV_HOST_NAME = 'alpha.linto.ai'
RELEASE_VERSION= sh( returnStdout: true,
script: "awk -v RS='' '/#/ {print; exit}' RELEASE.md | head -1 | sed 's/#//' | sed 's/ //'"
)
PACKAGE_VERSION = sh( returnStdout: true,
script : "awk -F'\"' '/\"version\": \".+\"/{ print \$4; exit; }' package.json"
)
REALM_AUTH = credentials('realm-verdaccio-auth') // Also load : REALM_AUTH_USR && REALM_AUTH_PSW
}
stages{
stage('NPM Master deployment'){
when{
branch 'master'
}
steps {
echo 'Prepare to deploy on npm'
script {
def published_version = sh( returnStdout: true,
script: "npm view . version"
)
checkVersion(PACKAGE_VERSION, RELEASE_VERSION, published_version)
nodejs(nodeJSInstallationName: 'latest', configId: NPM_CONFIG_ID) {
sh 'npm config ls'
// sh 'npm prune'
// sh 'npm install'
// sh 'npm publish'
}
}
echo 'Deploy done'
}
}
stage('Stage prod re-deployment'){
when{
branch 'master'
}
steps{
echo 'Prepare to deploy on ${PROD_HOST_NAME}'
script {
//remoteSsh(true)
}
}
}
stage('Verdaccio Next publish'){
when{
branch 'next'
}
steps {
echo 'Prepare to deploy on verdaccio'
script {
def published_version = sh( returnStdout: true,
script: "npm config set registry http://${REALM_AUTH_USR}:${REALM_AUTH_PSW}@${REGISTRY_DEV_HOST} && npm view . version"
)
checkVersion(PACKAGE_VERSION, RELEASE_VERSION, published_version)
nodejs(nodeJSInstallationName: 'latest', configId: VERDACCIO_CONFIG_ID) {
sh 'npm config ls'
// sh 'npm prune'
// sh 'npm install'
// sh 'npm publish'
}
}
echo 'Deploy done'
}
}
stage('Verdaccio dev deployment'){
when{
branch 'next'
}
steps{
echo 'Prepare to deploy on ${DEV_HOST_NAME}'
script {
//remoteSsh(false)
}
}
}
}// end stages
}
void checkVersion(package_version, release_version, published_version){
echo "Release VERSION : ${release_version}"
echo "Package VERSION : ${package_version}"
echo "Published VERSION : ${published_version}"
if(package_version != release_version){
error 'RELEASE.md and package.json version don\'t match'
}
if(package_version == published_version){
error 'Same version cannot be publish again'
}
echo "VERSION OK"
}
void remoteSsh(isBranchMaster = false){
def remote = [:]
def command = ""
remote.allowAnyHosts = true
if(isBranchMaster == true){ // Deploy production docker
remote.name = "linto-staging"
remote.host = PROD_HOST_NAME
}else{ // Deploy dev docker
remote.name = "linto-dev-staging"
remote.host = DEV_HOST_NAME
command = "./linto-platform-dev-stack/script/test.sh"
}
withCredentials([sshUserPrivateKey(credentialsId: 'ssh_stage', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
remote.identityFile = identity
remote.user = userName
sshCommand remote: remote, command: command
}
}