-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
97 lines (85 loc) · 2.96 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
import groovy.json.JsonOutput
def slackNotificationChannel = 'builds'
def notifySlack(text, channel, attachments) {
def slackURL = 'https://hooks.slack.com/services/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'
def jenkinsIcon = 'https://wiki.jenkins-ci.org/download/attachments/2916393/logo.png'
def payload = JsonOutput.toJson([text: text,
channel: channel,
username: "Jenkins",
icon_url: jenkinsIcon,
attachments: attachments
])
sh "curl -X POST --data-urlencode \'payload=${payload}\' ${slackURL}"
}
def appImg = null
pipeline {
agent any
stages {
stage('Build Image') {
steps {
script{
appImg = docker.build('robsdudeson/blog:latest')
}
}
}
stage('Reset DB') {
steps {
sh "docker-compose run app wait-for-it db:3306 -- rake db:reset"
}
}
stage('Run Tests'){
steps {
sh "docker-compose run app wait-for-it db:3306 -- rake test"
}
}
stage('Publish Image To Registry'){
steps {
script{
docker.withRegistry('https://registry.hub.docker.com','hub.docker.com - credentials'){
appImg.push(env.BRANCH_NAME)
switch (env.BRANCH_NAME){
case "master":
appImg.push('latest')
break
case "develop":
appImg.push('latest-develop')
break
}
}
}
}
}
stage('Deploy Image to Dev Env'){
steps{
script {
switch (env.BRANCH_NAME){
case "master":
sh 'scp docker-compose.deploy.yml [email protected]:/home/jenkins/blog/docker-compose.deploy.yml'
sh 'scp deploy.sh [email protected]:/home/jenkins/blog/deploy.sh'
sh 'ssh [email protected] chmod +x /home/jenkins/blog/deploy.sh'
sh 'ssh [email protected] /home/jenkins/blog/deploy.sh'
break
case "develop":
//sh 'echo its broke on the server side ... will check on it when i get a minute lawlzzzzzz'
sh 'scp docker-compose.deploy.yml [email protected]:/home/jenkins/blog/docker-compose.deploy.yml'
sh 'scp deploy.sh [email protected]:/home/jenkins/blog/deploy.sh'
sh 'ssh [email protected] chmod +x /home/jenkins/blog/deploy.sh'
sh 'ssh [email protected] /home/jenkins/blog/deploy.sh'
break
}
}
}
}
}
post {
always {
sh "docker-compose down -v"
}
success{
notifySlack("SUCCESS: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] ${env.BUILD_URL}", slackNotificationChannel, [])
}
failure{
notifySlack("FAILED: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] ${env.BUILD_URL}", slackNotificationChannel, [])
}
}
}