-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-docker-ansible
61 lines (60 loc) · 1.39 KB
/
Jenkinsfile-docker-ansible
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
pipeline {
agent none
stages {
stage('Checkout') {
agent any
steps {
git branch: 'main', url: 'https://github.com/crown2012/source-maven-java-spring-hello-webapp.git'
}
}
stage('Build') {
agent {
docker { image 'maven:3-openjdk-8' }
}
steps {
sh 'mvn clean package -DskipTests=true'
}
}
stage('Test') {
agent {
docker { image 'maven:3-openjdk-8' }
}
steps {
sh 'mvn test'
}
}
stage('Build Docker Image') {
agent any
steps {
sh 'docker image build -t myweb .'
}
}
stage('Tag Docker Image') {
agent any
steps {
sh 'docker image tag myweb hotak/myweb:$BUILD_NUMBER'
sh 'docker image tag myweb hotak/myweb:latest'
}
}
stage('Publish Docker Image') {
agent any
steps {
withDockerRegistry(credentialsId: 'docker-hub-token', url: 'https://index.docker.io/v1/') {
sh 'docker image push hotak/myweb:$BUILD_NUMBER'
sh 'docker image push hotak/myweb:latest'
}
}
}
stage('Run Docker Container') {
agent {
docker {
image 'c1t1d0s7/jenkins-ansible'
args '-u 0:0 -e DOCKER_HOST=tcp://192.168.56.104:2375'
}
}
steps {
ansiblePlaybook(playbook: 'docker-container-deploy.yaml')
}
}
}
}