-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontJenkinsFile
More file actions
67 lines (58 loc) · 1.78 KB
/
frontJenkinsFile
File metadata and controls
67 lines (58 loc) · 1.78 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
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS = credentials('docker')
COMPOSE_FILE_PATH = '/home/goushaa/deploy/docker-compose.yaml'
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', credentialsId: 'github', url: 'https://github.com/Twitter-Clone-Project/Front-End.git'
}
}
stage('Build') {
steps {
echo 'Building App....'
sh 'npm install'
sh 'npm run build'
}
}
stage('Docker') {
steps {
echo 'Dockerizing Front....'
sh 'docker build -t goushaa/frontend:latest .'
}
}
stage('Test') {
steps {
echo 'Running Tests....'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
sh 'docker push goushaa/frontend:latest'
sh 'docker logout'
}
}
}
post {
always {
echo 'Cleaning up...'
script {
// Stop and remove containers defined in the docker-compose.yml file
sh 'docker-compose -f $COMPOSE_FILE_PATH down'
// Remove images with the repository goushaa/frontend and no tag (dangling)
sh 'docker rmi $(docker images -f "dangling=true" -q)'
}
}
success {
echo 'Starting docker-compose...'
script {
// Start docker-compose
sh 'docker-compose -f $COMPOSE_FILE_PATH up -d'
}
}
}
}