-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
104 lines (82 loc) · 2.94 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
node ("jenkins-slave") {
//update variables bellow
//meaningful app name
def app_name = "ynd_phx_bootstrap_app"
def registry_url
def registry_creds
def dcos_dr_tag
def marathon_url
def marathon_id
def dcos_creds
//docker registry url
withCredentials([[$class: 'StringBinding', credentialsId: 'YND_PHX_REGISTRY_URL', variable: 'REGISTRY_URL']]) {
registry_url = REGISTRY_URL
}
//docker registry password
withCredentials([[$class: 'StringBinding', credentialsId: 'YND_PHX_REGISTRY_CREDS', variable: 'REGISTRY_CREDS']]) {
registry_creds = REGISTRY_CREDS
}
//docker registry tag name
withCredentials([[$class: 'StringBinding', credentialsId: 'YND_PHX_DCOS_DR', variable: 'TAG']]) {
dcos_dr_tag = TAG
}
//marathon url
withCredentials([[$class: 'StringBinding', credentialsId: 'YND_PHX_MARATHON_URL', variable: 'MARATHON_URL']]) {
marathon_url = MARATHON_URL
}
//marathon app id
withCredentials([[$class: 'StringBinding', credentialsId: 'YND_PHX_MARATHON_ID', variable: 'MARATHON_ID']]) {
marathon_id = MARATHON_ID
}
//marathon credentials
withCredentials([[$class: 'StringBinding', credentialsId: 'YND_PHX_DCOS_CREDS', variable: 'DCOS_CREDS']]) {
dcos_creds = DCOS_CREDS
}
def deployment_result = "STARTED"
def marathon_json = "marathon.json"
stage('Checkout') {
echo "Checkout"
checkout scm
}
def tag = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim()
stage('Development build & Syntax Check') {
sh("cp .env.example .env")
sh("/usr/local/bin/docker-compose build")
sh("/usr/local/bin/docker-compose run --rm app mix do deps.get, compile, credo --strict")
}
stage('Type checking') {
sh("/usr/local/bin/docker-compose run --rm app mix dialyzer --halt-exit-status --no-compile --no-check")
}
stage('Unit Tests') {
sh("/usr/local/bin/docker-compose run --rm app mix test")
sh("/usr/local/bin/docker-compose down")
junit 'build/report/junit/*.xml'
}
if(isOnDevelop()) {
stage("Setup marathon files") {
withCredentials([file(credentialsId: 'YND_PHX_MARATHON_JSON', variable: 'MARATHON_JSON')]) {
withCredentials([file(credentialsId: 'YND_PHX_MARATHON_DB_JSON', variable: 'MARATHON_DB_JSON')]) {
sh("cp \"$MARATHON_JSON\" ./marathon.json")
sh("cp \"$MARATHON_DB_JSON\" ./marathon-db.json")
}
}
}
stage("Production build") {
image = docker.build("${app_name}:${tag}", "-f rel/Dockerfile .")
}
stage("Promote") {
docker.withRegistry("${registry_url}","${registry_creds}") {
image.push("${tag}")
}
}
stage("Deployment") {
marathon credentialsId: "${dcos_creds}", docker: "${dcos_dr_tag}/${app_name}:${tag}", filename: "${marathon_json}", forceUpdate: true, id: "${marathon_id}", url: "${marathon_url}"
}
}
stage('Dev Tests') {
echo "Test Dev"
}
}
def isOnDevelop() {
return !env.BRANCH_NAME || env.BRANCH_NAME == "develop";
}