-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjenkinsfile
84 lines (75 loc) · 2.33 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
pipeline{
environment{
DOCKERHUB_REGISTRY = "kdesh2001/sportr"
DOCKERHUB_CREDENTIALS = credentials('Dockerhub')
}
agent any
stages{
stage('Cloning the repo'){
steps{
git branch: 'main',
url:'https://github.com/kdesh2001/SportR.git'
}
}
stage('Setting up the testDB'){
steps{
sh "docker run -d -p 2718:27017 --name mongodb_test mongo:4.2"
}
}
stage("Testing Api"){
steps{
sh '''
cd backend
npm install
npm run test
cd ..
'''
}
}
stage("closing testDB"){
steps{
sh '''
docker stop mongodb_test
docker rm mongodb_test
'''
}
}
stage('Build Docker Images for frontend and backend'){
steps{
sh "docker build -t $DOCKERHUB_REGISTRY-frontend:latest SportR-frontend/"
sh "docker build -t $DOCKERHUB_REGISTRY-backend:latest backend/"
}
}
stage('Login to Docker Hub') {
steps {
sh "echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin"
}
}
stage('Push docker images to hub') {
steps{
sh "docker push $DOCKERHUB_REGISTRY-backend:latest"
sh "docker push $DOCKERHUB_REGISTRY-frontend:latest"
}
}
stage('Clean docker images'){
steps{
script{
sh 'docker container prune -f'
sh 'docker image prune -f'
}
}
}
stage('Step 6: Ansible Deployment'){
steps{
ansiblePlaybook becomeUser: null,
colorized: true,
credentialsId: 'localhost',
disableHostKeyChecking: true,
installation: 'Ansible',
inventory: 'Deployment/inventory',
playbook: 'Deployment/deploy.yml',
sudoUser: null
}
}
}
}