This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
64 lines (57 loc) · 1.76 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
pipeline {
agent {
node {
label 'worker_medium'
}
}
options {
timestamps()
}
parameters {
string(name: 'INCLUDEOS_BRANCH', defaultValue: 'dev')
}
environment {
IMAGE_NAME = "includeos/includeos-common:${params.INCLUDEOS_BRANCH}"
}
stages {
stage('Build') {
steps {
script {
// Pull latest image from docker hub
def common = docker.image("${IMAGE_NAME}")
common.pull()
String HUB_ID = sh (returnStdout: true, script: "sudo docker images -q ${IMAGE_NAME}").trim()
// Build with latest $INCLUDEOS_BRANCH
def localImg = docker.build("${IMAGE_NAME}",
"-f Dockerfile.common --build-arg TAG=${params.INCLUDEOS_BRANCH} .")
String BUILT_ID = sh (returnStdout: true, script: "sudo docker images -q ${IMAGE_NAME}").trim()
// Compare to see if anything new was built
echo "HUB_ID: ${HUB_ID} BUILT_ID: ${BUILT_ID}"
if ( HUB_ID == BUILT_ID ) {
sh 'echo False > .new_content'
} else {
sh 'echo True > .new_content'
}
}
}
}
stage('Upload') {
steps {
script {
// Read file to see if anything new has been committed
def content = readFile('.new_content').trim()
echo "content: ${content} hey"
if ( content == "True" ) {
echo "Uploading ${IMAGE_NAME}"
def localImg = docker.image("${IMAGE_NAME}")
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub_mnordsletten') {
localImg.push()
}
} else {
echo "The image: ${IMAGE_NAME} already exists on docker hub"
}
}
}
}
}
}