-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
53 lines (53 loc) · 1.8 KB
/
Jenkinsfile
File metadata and controls
53 lines (53 loc) · 1.8 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
pipeline {
agent any
environment {
DOCKER_CRED = credentials('dockerhub-username')
// Use Jenkins BUILD_NUMBER as the image tag
IMAGE_TAG = "${BUILD_NUMBER}"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Code Quality') {
steps {
echo 'Running linting...'
sh 'cd frontend && npm install && npm run lint'
}
}
stage('Unit Tests') {
steps {
echo 'Running tests...'
sh 'pip install --break-system-packages pytest flask prometheus_client werkzeug'
sh 'cd backend && /var/lib/jenkins/.local/bin/pytest'
}
}
stage('Build Docker Images') {
steps {
timeout(time: 10, unit: 'MINUTES') {
script {
sh 'docker build -t $DOCKER_CRED_USR/devops-project-3-frontend:$IMAGE_TAG ./frontend'
sh 'docker build -t $DOCKER_CRED_USR/devops-project-3-backend:$IMAGE_TAG ./backend'
}
}
}
}
stage('Push to DockerHub') {
steps {
script {
sh 'echo $DOCKER_CRED_PSW | docker login -u $DOCKER_CRED_USR --password-stdin'
sh 'docker push $DOCKER_CRED_USR/devops-project-3-frontend:$IMAGE_TAG'
sh 'docker push $DOCKER_CRED_USR/devops-project-3-backend:$IMAGE_TAG'
}
}
}
}
post {
success {
// Trigger the deployment pipeline with the new tag
build job: 'DevOps-Deploy', parameters: [string(name: 'IMAGE_TAG', value: "${env.BUILD_NUMBER}")], wait: false
}
}
}