-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
54 lines (47 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
pipeline {
agent {
node {
label 'jenkins-agent'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '30'))
timestamps()
}
parameters {
string(name: "DockerHub_Name", defaultValue: 'furritos', description: 'DockerHub repository name')
string(name: "Branch_Name", defaultValue: 'master', description: '')
string(name: "Image_Name", defaultValue: 'docker-btdex', description: 'Image name')
string(name: "Image_Tag", defaultValue: 'latest', description: 'Image tag')
booleanParam(name: "PushImage", defaultValue: true)
}
stages {
stage("Build Docker images") {
steps {
script {
echo "Bulding docker images"
def buildArgs = "-f Dockerfile ."
docker.build("${params.Image_Name}:${params.Image_Tag}", buildArgs)
}
}
}
stage("Push to Dockerhub") {
when {
equals expected: "true",
actual: "${params.PushImage}"
}
steps {
script {
echo "Pushing the image to Docker hub"
def localImage = "${params.Image_Name}:${params.Image_Tag}"
def repositoryName = "${params.DockerHub_Name}/${localImage}"
sh "docker tag ${localImage} ${repositoryName} "
docker.withRegistry("", "DockerHubCredential") {
def image = docker.image("${repositoryName}");
image.push()
}
}
}
}
}
}