-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfileBuildPush
More file actions
44 lines (41 loc) · 1.73 KB
/
JenkinsfileBuildPush
File metadata and controls
44 lines (41 loc) · 1.73 KB
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
// Pod Template
def cloud = env.CLOUD ?: "kubernetes"
def registryCredsID = env.REGISTRY_CREDENTIALS ?: "registry-credentials-id"
def serviceAccount = env.SERVICE_ACCOUNT ?: "jenkins"
// Pod Environment Variables
def namespace = env.NAMESPACE ?: "default"
def registry = env.REGISTRY ?: "mycluster.icp:8500"
podTemplate(label: 'mypod', cloud: cloud, serviceAccount: serviceAccount, namespace: namespace, envVars: [
envVar(key: 'NAMESPACE', value: namespace),
envVar(key: 'REGISTRY', value: registry)
],
volumes: [
hostPathVolume(hostPath: '/etc/docker/certs.d', mountPath: '/etc/docker/certs.d'),
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')
],
containers: [
containerTemplate(name: 'docker' , image: 'docker:17.06.1-ce', ttyEnabled: true, command: 'cat')
]) {
node('mypod') {
checkout scm
container('docker') {
stage('Build Docker Image') {
sh """
#!/bin/bash
docker build -t ${env.REGISTRY}/${env.NAMESPACE}/bluecompute-ce-web:${env.BUILD_NUMBER} .
"""
}
stage('Push Docker Image to Registry') {
withCredentials([usernamePassword(credentialsId: registryCredsID,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD')]) {
sh """
#!/bin/bash
docker login -u ${USERNAME} -p ${PASSWORD} ${env.REGISTRY}
docker push ${env.REGISTRY}/${env.NAMESPACE}/bluecompute-ce-web:${env.BUILD_NUMBER}
"""
}
}
}
}
}