-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
55 lines (53 loc) · 1.54 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
pipeline {
agent any
tools {
maven "Maven3"
}
stages {
// stage('Git Checkout') {
// steps {
// git branch: 'main', changelog: false, poll: false, url: 'https://github.com/SmitMehta510/SPE-mini-project.git'
// }
// }
stage('Maven build') {
steps {
sh "mvn clean install"
}
}
stage('Build docker image'){
steps{
script{
sh 'docker build -t smitmehta510/scientific_calculator .'
}
}
}
stage('Stop and Remove Existing Container') {
steps {
script {
sh 'docker stop scientific_calculator || true'
sh 'docker rm -f scientific_calculator || true'
}
}
}
stage('Docker image push'){
steps{
script{
withCredentials([string(credentialsId: 'smit', variable: 'DockerCredential')]) {
sh 'docker login -u smitmehta510 -p ${DockerCredential}'
}
sh 'docker push smitmehta510/scientific_calculator'
}
}
}
stage('Run Ansible Playbook') {
steps {
script {
ansiblePlaybook(
playbook: 'deploy.yml',
inventory: 'inventory'
)
}
}
}
}
}