forked from eclipse-zenoh/zenoh-plugin-dds
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
70 lines (65 loc) · 2.18 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
pipeline {
agent { label 'MacMini' }
options { skipDefaultCheckout() }
parameters {
gitParameter(name: 'GIT_TAG',
type: 'PT_BRANCH_TAG',
description: 'The Git tag to checkout. If not specified "master" will be checkout.',
defaultValue: 'master')
string(name: 'DOCKER_TAG',
description: 'An extra Docker tag (e.g. "latest"). By default GIT_TAG will also be used as Docker tag',
defaultValue: '')
booleanParam(name: 'PUBLISH_DOCKER_HUB',
description: 'Publish the resulting artifacts to DockerHub.',
defaultValue: false)
}
environment {
DOCKER_IMAGE="eclipse/zenoh-bridge-dds"
LABEL = get_label()
}
stages {
stage('[MacMini] Checkout Git TAG') {
steps {
deleteDir()
checkout([$class: 'GitSCM',
branches: [[name: "${params.GIT_TAG}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://github.com/eclipse-zenoh/zenoh-plugin-dds.git']]
])
}
}
stage('[MacMini] Docker build') {
steps {
sh '''
if [ -n "${DOCKER_TAG}" ]; then
export EXTRA_TAG="-t ${DOCKER_IMAGE}:${DOCKER_TAG}"
fi
docker build -t ${DOCKER_IMAGE}:${LABEL} ${EXTRA_TAG} .
'''
}
}
stage('[MacMini] Publish to Docker Hub') {
when { expression { return params.PUBLISH_DOCKER_HUB }}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub-bot',
passwordVariable: 'DOCKER_HUB_CREDS_PSW', usernameVariable: 'DOCKER_HUB_CREDS_USR')])
{
sh '''
docker login -u ${DOCKER_HUB_CREDS_USR} -p ${DOCKER_HUB_CREDS_PSW}
docker push ${DOCKER_IMAGE}:${LABEL}
if [ -n "${DOCKER_TAG}" ]; then
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
fi
docker logout
'''
}
}
}
}
}
def get_label() {
return env.GIT_TAG.startsWith('origin/') ? env.GIT_TAG.minus('origin/') : env.GIT_TAG
}