-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
75 lines (62 loc) · 2.48 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
node {
stage('🚧 Checkout') {
println("☘️" + env.BRANCH_NAME)
checkout scm
}
stage('📦 Build') {
println("🚧 building project")
def nodeHome = tool name: 'nodejs', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${nodeHome}/bin:${env.PATH}"
sh "npm install"
sh "npm test"
}
stage('🚢 Check if Deploy') {
println("☘️" + env.BRANCH_NAME)
if(env.BRANCH_NAME.equals("master")) {
stage('Deploy to production 🚀') {
println("🎉 it's time to deploy to Clever-Cloud 🍾")
//it's done automatically by Clever-Cloud
}
} else {
// =======COMMIT MESSAGE========
commitMessage = sh(returnStdout: true, script: "git log -1 --pretty=%B").trim()
println("👋 commit message: ${commitMessage}")
if(commitMessage.startsWith("deploy")) {
//TODO, find something to destroy the scaler
scalerName = commitMessage.split(" ")[1]
// I want to use it for test deployment
stage('Time to test 🚧') {
println("👷 it's time to test your feature branch: ${env.BRANCH_NAME}")
def nodeHome = tool name: 'nodejs6103', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
//checkout scm
env.PATH = "${nodeHome}/bin:${env.PATH}"
sh "clever create -t node ${scalerName} --org wey-yu --region par --alias ${scalerName}"
// get the application id
def applicationId = sh(
script: '''grep -o '"app_id": *"[^"]*"' .clever.json | grep -o '"[^"]*"$' ''',
returnStdout: true
).trim().split('"').last()
println "🙂: ${applicationId}"
sh "clever env set PORT 8080 --alias ${scalerName}"
sh "clever scale --flavor pico --alias ${scalerName}"
//sh "git checkout master"
sh "git checkout ${env.BRANCH_NAME}"
sh "git branch"
sh '''
if [ `git remote show` == "clever" ]
then
git remote rm clever
fi
'''
sh "git remote add clever git+ssh://[email protected]/${applicationId}.git"
//sh "git push clever master"
sh "git push clever ${env.BRANCH_NAME}:master"
} // end stage
} else {
stage('nothing to do 😀') {
println("have a nice day")
}
} // end of if
}
}
}