-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile-2
114 lines (114 loc) · 4.56 KB
/
Jenkinsfile-2
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
105
106
107
108
109
110
111
112
113
114
pipeline {
agent any
environment {
AWS_ACCESS_KEY_ID = credentials("aws-access-key-id")
AWS_SECRET_ACCESS_KEY = credentials("aws-secret-access-key")
AWS_SESSION_TOKEN = credentials("aws-session-token")
}
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 rmi cpdrenato/laravel8cicd-jenkins"
sh "docker build -t cpdrenato/laravel8cicd-jenkins --no-cache ."
}
}
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 cpdrenato/laravel8cicd-jenkins"
}
}
stage("Deploy to staging") {
steps {
sh "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
sh "export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
sh "export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}"
sh "ssh-agent sh -c 'ssh-add /etc/ansible/pem/key.pem && ansible-playbook /etc/ansible/playbook/playbook-staging-run.yml'"
}
}
stage("Acceptance test curl") {
steps {
sleep 20
sh "chmod +x acceptance_test.sh && ./acceptance_test.sh"
}
}
stage("Acceptance test codeception") {
steps {
sh "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
sh "export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
sh "export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}"
sh "ssh-agent sh -c 'ssh-add /etc/ansible/pem/key.pem && ansible-playbook /etc/ansible/playbook/playbook-staging-acceptance.yml'"
}
post {
always {
sh "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
sh "export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
sh "export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}"
sh "ssh-agent sh -c 'ssh-add /etc/ansible/pem/key.pem && ansible-playbook /etc/ansible/playbook/playbook-staging-stop.yml'"
}
}
}
stage("Release") {
steps {
sh "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
sh "export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
sh "export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}"
sh "ssh-agent sh -c 'ssh-add /etc/ansible/pem/key.pem && ansible-playbook /etc/ansible/playbook/playbook-production-run.yml'"
}
}
stage("Smoke test") {
steps {
sleep 20
sh "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
sh "export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
sh "export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}"
sh "ssh-agent sh -c 'ssh-add /etc/ansible/pem/key.pem && ansible-playbook /etc/ansible/playbook/playbook-production-acceptance.yml'"
}
}
}
}