forked from indigo-dc/orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
77 lines (68 loc) · 2.79 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
pipeline {
agent {
node { label 'jenkinsworker00' }
}
environment {
DOCKER_HUB_CREDENTIALS = 'docker-hub-credentials'
DOCKER_HUB_IMAGE_NAME = 'indigopaas/orchestrator'
HARBOR_CREDENTIALS = 'harbor-paas-credentials'
HARBOR_IMAGE_NAME = 'datacloud-middleware/orchestrator'
}
stages {
stage('checkout and compiling') {
agent {
docker {
label 'jenkinsworker00'
image 'maven:3.5.4-ibmjava-8'
args '--privileged'
reuseNode true
}
}
steps {
configFileProvider([configFile(fileId: 'maven-nexus-settings.xml', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS editorconfig:format'
sh 'mvn -s $MAVEN_SETTINGS clean install'
}
}
}
stage('Build and tag Docker Image') {
steps {
script {
def dockerImage = docker.build("orchestrator:${env.BRANCH_NAME}", "-f docker/Dockerfile docker/")
sh("docker tag orchestrator:${env.BRANCH_NAME} ${HARBOR_IMAGE_NAME}:${env.BRANCH_NAME}")
sh("docker tag orchestrator:${env.BRANCH_NAME} ${DOCKER_HUB_IMAGE_NAME}:${env.BRANCH_NAME}")
}
}
}
stage('Push to Docker Hub and Harbor') {
parallel {
stage('Push to Docker Hub') {
steps {
script {
// Retrieve the Docker image object from the previous stage
def dockerhubImage = docker.image("${DOCKER_HUB_IMAGE_NAME}:${env.BRANCH_NAME}")
// Login to Docker Hub
docker.withRegistry('https://index.docker.io/v1/', DOCKER_HUB_CREDENTIALS) {
// Push the Docker image to Docker Hub
dockerhubImage.push()
}
}
}
}
stage('Push to Harbor') {
steps {
script {
// Retrieve the Docker image object from the previous stage
def harborImage = docker.image("${HARBOR_IMAGE_NAME}:${env.BRANCH_NAME}")
// Login to Harbor
docker.withRegistry('https://harbor.cloud.infn.it', HARBOR_CREDENTIALS) {
// Push the Docker image to Harbor
harborImage.push()
}
}
}
}
}
}
}
}