-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
85 lines (63 loc) · 3.15 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
node("docker") {
currentBuild.result = "SUCCESS"
try {
stage "Building"
checkout scm
// ${env.GIT_COMMIT} doesn't work D:
sh "git rev-parse --short HEAD > .git/git_commit"
branch_name = "${env.BRANCH_NAME}".replaceAll("/", "_")
// git_commit = readFile(".git/git_commit").replace("\n", "").replace("\r", "")
git_commit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
build_name = "${branch_name}--${git_commit}"
echo "Building urbo-www/${build_name}"
if (branch_name == "master") {
sh "cp src/js/Config.production.js src/js/Config.js"
deploy_to = "prod"
}
else if (branch_name == "staging") {
sh "cp src/js/Config.staging.js src/js/Config.js"
deploy_to = "staging"
}
else if (branch_name == "dev") {
sh "cp src/js/Config.dev.js src/js/Config.js"
deploy_to = "dev"
}
else if (branch_name == "dev-andalucia") {
sh "cp src/js/Config.dev-and.js src/js/Config.js"
deploy_to = "dev-andalucia"
}
else{
sh "cp src/js/Config.dev.js src/js/Config.js"
}
sh "git submodule init && git submodule update"
sh "docker build --pull=true -t geographica/urbo_core_www ."
stage "Testing"
/*
* Because still there are no tests, we only run the builder
*/
// sh "docker run -i -e DISPLAY=:99 -e CHROME_BIN=chrome-browser --name urbo_www--${build_name} geographica/urbo_core_www"
echo "Testing urbo-www/${build_name}"
// Testing with PhantomJS. TODO: Chrome testing
sh "docker run -i -e DISPLAY=:99 -e CHROME_BIN=chrome-browser --rm --name urbo_www--${build_name} geographica/urbo_core_www npm run test"
} catch (error) {
currentBuild.result = "FAILURE"
echo "urbo-www/${build_name} failed: ${error}"
throw error
} finally {
stage "Cleaning"
// If in the future when we need to clean something of the real tests, this will be the place
echo "Cleaning urbo-www/${build_name}"
if (currentBuild.result == "SUCCESS" && ["master", "dev"].contains(branch_name)) {
stage "Deploying"
withCredentials([[$class: 'UsernamePasswordMultiBinding',credentialsId: 'dockerhub',usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh "docker login -u ${USERNAME} -p ${PASSWORD}"
sh "docker tag geographica/urbo_core_www geographica/urbo_core_www:${git_commit}"
sh "docker push geographica/urbo_core_www:${git_commit}"
sh "ansible urbo-frontend-${deploy_to} -a '/data/app/UrboCore-www/deploy.sh ${branch_name}'"
}
} else if (branch_name == "dev-andalucia") {
stage "Deploying"
sh "ansible urbo-frontend-${deploy_to} -a '/data/app/UrboCore-www/deploy-and.sh ${branch_name}'"
}
}
}