This repository has been archived by the owner on Jul 18, 2018. It is now read-only.
/
Jenkinsfile
72 lines (63 loc) · 2.8 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
// Configuration variables
github_org = "samsung-cnct"
quay_org = "samsung_cnct"
publish_branch = "master"
image_tag = "${env.RELEASE_VERSION}" != "null" ? "${env.RELEASE_VERSION}" : "latest"
project_name = "k2-logging-fluent-bit-daemonset"
podTemplate(label: "${project_name}", containers: [
containerTemplate(name: 'jnlp', image: "quay.io/${quay_org}/custom-jnlp:0.1", args: '${computer.jnlpmac} ${computer.name}'),
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true)
], volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
hostPathVolume(hostPath: '/var/lib/docker/scratch', mountPath: '/mnt/scratch'),
secretVolume(mountPath: '/home/jenkins/.docker/', secretName: 'samsung-cnct-quay-robot-dockercfg')
]) {
node("${project_name}") {
customContainer('docker') {
// add a docker rmi/docker purge/etc.
stage('Checkout') {
checkout scm
// retrieve the URI used for checking out the source
// this assumes one branch with one uri
git_uri = scm.getRepositories()[0].getURIs()[0].toString()
git_branch = scm.getBranches()[0].toString()
}
// build new version of kraken-tools image on 'docker' container
stage('Build') {
kubesh "docker build -t ${project_name}:${env.JOB_BASE_NAME}.${env.BUILD_ID} ./init"
}
stage('Test') {
// Docker container related tests, if any, go here
}
// only push from master. check that we are on samsung-cnct fork
stage('Publish') {
if (git_branch.contains(publish_branch) && git_uri.contains(github_org)) {
kubesh "docker tag ${project_name}:${env.JOB_BASE_NAME}.${env.BUILD_ID} quay.io/${quay_org}/${project_name}:${image_tag}"
kubesh "docker push quay.io/${quay_org}/${project_name}:${image_tag}"
} else {
echo "Not pushing to docker repo:\n BRANCH_NAME='${env.BRANCH_NAME}'\n GIT_BRANCH='${git_branch}'\n git_uri='${git_uri}'"
}
}
}
}
}
def kubesh(command) {
if (env.CONTAINER_NAME) {
if ((command instanceof String) || (command instanceof GString)) {
command = kubectl(command)
}
if (command instanceof LinkedHashMap) {
command["script"] = kubectl(command["script"])
}
}
sh(command)
}
def kubectl(command) {
"kubectl exec -i ${env.HOSTNAME} -c ${env.CONTAINER_NAME} -- /bin/sh -c 'cd ${env.WORKSPACE} && ${command}'"
}
def customContainer(String name, Closure body) {
withEnv(["CONTAINER_NAME=$name"]) {
body()
}
}
// vi: ft=groovy