-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
53 lines (43 loc) · 1.27 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
pipeline{
agent any
tools{
maven 'maven3'
}
environment {
DOCKER_TAG = getVersion()
}
stages{
stage('SCM'){
steps{
git 'https://github.com/mahesh1b/Docker-Ansible-Jenkins'
}
}
stage('Maven Build'){
steps{
sh 'mvn clean package'
}
}
stage('Docker Build'){
steps{
sh 'docker build . -t mahesh1b/myapp:${DOCKER_TAG} '
}
}
stage('Docker Push'){
steps{
withCredentials([string(credentialsId: 'docker-hub', variable: 'pass')]) {
sh 'docker login -u mahesh1b -p ${pass}'
}
sh 'docker push mahesh1b/myapp:${DOCKER_TAG} '
}
}
stage('Docker Deploy'){
steps{
ansiblePlaybook credentialsId: 'dev', disableHostKeyChecking: true, extras: "-e DOCKER_TAG=${DOCKER_TAG}", installation: 'ansible', inventory: 'dev.inv', playbook: 'deploy-docker.yml'
}
}
}
}
def getVersion(){
def commitHash = sh label: '', returnStdout: true, script: 'git rev-parse --short HEAD'
return commitHash
}