This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathJenkinsfile
59 lines (55 loc) · 2.57 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
podTemplate(label: 'buildDockerContainer', containers: [
containerTemplate(name: 'docker', image: 'docker', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm', ttyEnabled: true, command: 'cat')
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
node('buildDockerContainer') {
def repo = checkout scm
def gitCommit = repo.GIT_COMMIT
def gitBranch = repo.GIT_BRANCH
def shortGitCommit = "${gitCommit[0..10]}"
stage('Build And Publish Docker Image') {
container('docker') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub',
usernameVariable: 'DOCKER_HUB_USER', passwordVariable: 'DOCKER_HUB_PASSWORD']]) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'hmda-platform-jenkins-service',
usernameVariable: 'DTR_USER', passwordVariable: 'DTR_PASSWORD']]) {
withCredentials([string(credentialsId: 'internal-docker-registry', variable: 'DOCKER_REGISTRY_URL')]){
sh "docker build --rm -t=${env.DOCKER_HUB_USER}/hmda-pub-ui ."
if (env.TAG_NAME != null || gitBranch == "master") {
if (gitBranch == "master") {
env.DOCKER_TAG = "latest"
} else {
env.DOCKER_TAG = env.TAG_NAME
}
sh """
docker tag ${env.DOCKER_HUB_USER}/hmda-pub-ui ${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
docker login -u ${env.DOCKER_HUB_USER} -p ${env.DOCKER_HUB_PASSWORD}
docker push ${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
docker tag ${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG} ${DOCKER_REGISTRY_URL}/${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
docker login ${DOCKER_REGISTRY_URL} -u ${env.DTR_USER} -p ${env.DTR_PASSWORD}
docker push ${DOCKER_REGISTRY_URL}/${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
docker image prune -f
"""
}
}
}
}
}
}
stage('Deploy') {
if (env.BRANCH_NAME == 'master') {
container('helm') {
sh "helm upgrade --install --force \
--namespace=default \
--values=kubernetes/hmda-pub-ui/values.yaml \
--set image.tag=latest \
hmda-pub-ui \
kubernetes/hmda-pub-ui"
}
}
}
}
}