-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
93 lines (92 loc) · 3.13 KB
/
Jenkinsfile
File metadata and controls
93 lines (92 loc) · 3.13 KB
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
pipeline {
agent any
options {
timeout(time: 10, unit: 'MINUTES')
disableConcurrentBuilds()
}
triggers{
bitbucketPush()
}
environment {
SLACK_CHANNEL = 'database-ops'
PYPI_FOLDER = 'django-calidae-database'
}
stages {
stage('Compile images') {
steps {
slackSend(message: "Start: Jenkins Build (${env.JOB_NAME}) - <${env.RUN_DISPLAY_URL}| Follow execution>", channel: "${env.SLACK_CHANNEL}", color: '3333FF')
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml build --force-rm --no-cache node'
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T node npm install --no-audit'
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml build --force-rm --no-cache django'
}
}
stage('Launch linters') {
parallel {
stage('Front Linter'){
steps{
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T node npm run lint'
}
}
stage('Django Linter'){
steps{
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T django python -m flake8'
}
}
}
}
stage('Launch tests') {
parallel {
stage('Django tests'){
steps{
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T django env "DB_NAME=test" python ./manage.py test'
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T django python ./manage.py migrate'
}
}
stage('Front tests'){
steps{
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T node npm test'
}
}
}
}
stage('Build and update pypi module') {
when {
branch 'master'
}
steps {
sh 'cd $WORKSPACE/backend/ && bumpr -s $BUILD_NUMBER'
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml run -T node npm run build'
sh 'pip3 wheel $WORKSPACE/backend/ --no-deps'
sh 'scp *.whl root@pypi.calidae.net:/pippackages/django/$PYPI_FOLDER/'
}
}
stage('Deploy to dev') {
when {
branch 'master'
}
steps {
ansiblePlaybook(
credentialsId: 'ansible_vault',
limit: 'calidae.dev.database',
playbook: '/opt/calidae/ansible/update.yml',
extras: '-v'
)
}
}
}
post {
always {
echo 'Stop docker machines'
sh 'docker-compose -f $WORKSPACE/docker-compose.test.yml rm --stop --force'
echo 'Cleaning environment'
sh 'sudo chown --recursive jenkins:jenkins $WORKSPACE'
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, cleanupMatrixParent: true, deleteDirs: true)
}
success {
slackSend(message: "Success: Jenkins Build (${env.JOB_NAME}) - <${env.RUN_DISPLAY_URL}| View execution>", channel: "${env.SLACK_CHANNEL}", color: '00FF00')
}
failure {
slackSend(message: "Failure: Jenkins Build (${env.JOB_NAME}) - <${env.RUN_DISPLAY_URL}| View execution>", channel: "${env.SLACK_CHANNEL}", color: 'FF0000')
}
}
}