-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile.groovy
62 lines (59 loc) · 2.02 KB
/
Jenkinsfile.groovy
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
def dockerImage
def dockerImageTag
pipeline {
agent any
stages {
stage('Build image') {
steps {
script {
dockerImage = docker.build("youtube-delete-tracker:${env.BRANCH_NAME}-${env.BUILD_ID}")
dockerImageTag = dockerImage.id
}
}
}
stage('Run tests') {
steps {
script {
dockerImage.inside('--network szeremi -e DB_HOST=mysql -e APP_ENV=testing') {
sh 'cd /var/www/html && php artisan migrate:fresh && vendor/bin/phpunit'
}
}
}
}
stage('Deploy') {
when {
anyOf {
branch 'master'
branch 'jenkins-declarative'
}
}
steps {
script {
def tag = 'youtube-delete-tracker'
if (env.BRANCH_NAME != 'master') {
// Implicit :latest must be changed to the branch name.
tag = "${tag}:${env.BRANCH_NAME}"
}
// Re-tag the image, because the deployment server is the same as the Jenkins server.
sh "docker tag ${dockerImage.id} ${tag}"
// Stop the docker image running under the same tag.
// Then, systemd should automatically run the container again, but with the updated image.
sh "docker stop ${tag} || true"
}
}
}
}
post {
always {
// Clean up the tag.
sh "docker rmi ${dockerImageTag}"
// Send email notification.
emailext (
body: '$DEFAULT_CONTENT',
to: '$DEFAULT_RECIPIENTS',
recipientProviders: [brokenTestsSuspects(), brokenBuildSuspects(), developers()],
subject: '$DEFAULT_SUBJECT'
)
}
}
}