-
Notifications
You must be signed in to change notification settings - Fork 78
/
Jenkinsfile
82 lines (82 loc) · 2.54 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
pipeline {
agent any
stages {
stage("Build") {
environment {
DB_HOST = credentials("laravel-host")
DB_DATABASE = credentials("laravel-database")
DB_USERNAME = credentials("laravel-user")
DB_PASSWORD = credentials("laravel-password")
}
steps {
sh 'php --version'
sh 'composer install'
sh 'composer --version'
sh 'cp .env.example .env'
sh 'echo DB_HOST=${DB_HOST} >> .env'
sh 'echo DB_USERNAME=${DB_USERNAME} >> .env'
sh 'echo DB_DATABASE=${DB_DATABASE} >> .env'
sh 'echo DB_PASSWORD=${DB_PASSWORD} >> .env'
sh 'php artisan key:generate'
sh 'cp .env .env.testing'
sh 'php artisan migrate'
}
}
stage("Unit test") {
steps {
sh 'php artisan test'
}
}
stage("Code coverage") {
steps {
sh "vendor/bin/phpunit --coverage-html 'reports/coverage'"
}
}
stage("Static code analysis larastan") {
steps {
sh "vendor/bin/phpstan analyse --memory-limit=2G"
}
}
stage("Static code analysis phpcs") {
steps {
sh "vendor/bin/phpcs"
}
}
stage("Docker build") {
steps {
sh "docker build -t danielgara/laravel8cd ."
}
}
stage("Docker push") {
environment {
DOCKER_USERNAME = credentials("docker-user")
DOCKER_PASSWORD = credentials("docker-password")
}
steps {
sh "docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD}"
sh "docker push danielgara/laravel8cd"
}
}
stage("Deploy to staging") {
steps {
sh "docker run -d --rm -p 80:80 --name laravel8cd danielgara/laravel8cd"
}
}
stage("Acceptance test curl") {
steps {
sleep 20
sh "chmod +x acceptance_test.sh && ./acceptance_test.sh"
}
}
stage("Acceptance test codeception") {
steps {
sh "vendor/bin/codecept run"
}
post {
always {
sh "docker stop laravel8cd"
}
}
}
}
}