-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
48 lines (41 loc) · 1.46 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
def defaults = [:]
defaults['version'] = 'latest'
def version = params.version == null ? defaults['version'] : params.version
def label = "worker-${UUID.randomUUID().toString()}"
def SERVICE_NAME = "firebase-auth-connector"
def dockerhubUser = "surfadvisor"
def registry = "${dockerhubUser}/${SERVICE_NAME}"
def registryCredential = 'dockerhub'
def REPOSITORY_TAG="${registry}:${version}"
def dockerImage = ''
podTemplate(label: label, serviceAccount: 'jenkins-stg', containers: [
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.16.0', command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
node(label) {
parameters {
string(defaultValue: defaults['version'], description: 'Dictionary version?', name: 'version')
}
stage('Clone git') {
git credentialsId: 'jenkins-github', url: "https://github.com/surfadvisor/${SERVICE_NAME}"
}
stage('Build image') {
container('docker') {
script {
dockerImage = docker.build("${REPOSITORY_TAG}")
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Deploy to Cluster') {
container('kubectl') {
sh 'kubectl apply -f ${WORKSPACE}/deploy.yaml'
}
}
}
}