Skip to content

Commit 8a5c145

Browse files
Add Jenkinsfile
1 parent fe1af22 commit 8a5c145

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

Jenkinsfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
pipeline {
2+
agent {
3+
node { label 'jenkinsworker00' }
4+
}
5+
6+
environment {
7+
8+
//DOCKER_HUB_CREDENTIALS = 'docker-hub-credentials'
9+
HARBOR_CREDENTIALS = 'harbor-paas-credentials'
10+
DOCKER_HUB_IMAGE_NAME = 'indigo-paas/orchestrator-dashboard'
11+
HARBOR_IMAGE_NAME = 'datacloud-middleware/orchestrator-dashboard'
12+
}
13+
14+
stages {
15+
stage('Build and Tag Docker Image') {
16+
17+
steps {
18+
script {
19+
// Build Docker image
20+
def dockerImage = docker.build("${DOCKER_HUB_IMAGE_NAME}:${env.BRANCH_NAME}", "-f docker/Dockerfile .")
21+
22+
// Tag the image for Harbor
23+
dockerImage.tag("${HARBOR_IMAGE_NAME}:${env.BRANCH_NAME}")
24+
25+
// Export the Docker image object for later stages
26+
env.DOCKER_IMAGE = dockerImage.id
27+
}
28+
}
29+
}
30+
31+
stage('Push to Docker Hub and Harbor') {
32+
parallel {
33+
stage('Push to Docker Hub') {
34+
steps {
35+
script {
36+
// Retrieve the Docker image object from the previous stage
37+
def dockerImage = docker.image(env.DOCKER_IMAGE)
38+
39+
// Login to Docker Hub
40+
docker.withRegistry('https://index.docker.io/v1/', DOCKER_HUB_CREDENTIALS) {
41+
// Push the Docker image to Docker Hub
42+
dockerImage.push()
43+
}
44+
}
45+
}
46+
}
47+
48+
stage('Push to Harbor') {
49+
steps {
50+
script {
51+
// Retrieve the Docker image object from the previous stage
52+
def dockerImage = docker.image(env.DOCKER_IMAGE)
53+
54+
// Login to Harbor
55+
docker.withRegistry('https://harbor.cloud.infn.it', HARBOR_CREDENTIALS) {
56+
// Push the Docker image to Harbor
57+
dockerImage.push()
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
post {
67+
success {
68+
echo 'Docker image build and push successful!'
69+
}
70+
failure {
71+
echo 'Docker image build and push failed!'
72+
}
73+
}
74+
}
75+

0 commit comments

Comments
 (0)