-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
85 lines (69 loc) · 2.29 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
pipeline {
agent{
label 'agent1'
}
triggers {
pollSCM('*/5 * * * *') // Polls the SCM every 5 minutes
}
stages {
stage('Install Dependencies') {
steps {
sh 'apt-get update && apt-get install -y python3 python3-venv'
// Create a Python virtual environment
sh 'python3 -m venv venv'
sh 'apt-get install -y python3-pip'
// Activate the virtual environment
sh '. ./venv/bin/activate && pip install -r requirements.txt && black --check .'
// Upgrade pip within the virtual environment
sh 'pip install --upgrade pip'
// Install dependencies from requirements.txt within the virtual environment
}
}
stage('Install Docker') {
steps {
sh 'curl -fsSL https://get.docker.com | sh'
}
}
stage('Lint tests') {
steps {
sh '''
. ./venv/bin/activate && \
flake8 . --count --ignore=W503,E501 --max-line-length=91 --show-source --statistics --exclude=venv && \
black --check --exclude venv .
'''
}
}
stage('Run Tests') {
steps {
sh '. ./venv/bin/activate && pytest'
}
}
stage('Build Docker Image') {
steps {
sh 'docker build -t khabdrick/test_app:v1 .'
}
}
stage('Push Docker Image to Registry') {
steps {
withCredentials([string(credentialsId: 'docker-password', variable: 'DOCKER_PASSWORD')]) {
sh 'docker login -u khabdrick -p $DOCKER_PASSWORD'
sh 'docker push khabdrick/test_app:v1'
}
}
}
}
post {
success {
emailext subject: 'CI/CD Pipeline Notification',
body: 'Your build was successful! ✨ 🍰 ✨',
to: 'muhamzyali@gmail.com',
attachLog: true
}
failure {
emailext subject: 'CI/CD Pipeline Notification. ',
body: 'Your build failed. Please investigate.❌ ❌ ❌ ',
attachLog: true,
to: 'muhamzyali@gmail.com'
}
}
}