-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
46 lines (44 loc) · 1.47 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
pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins: agent
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
tty: true
command:
- cat
"""
}
}
environment {
DOCKER_REGISTRY = 'registry.iswleuven.be'
IMAGE_NAME = 'student-projects/isp-class-schedule/frontend'
API_URL = credentials('api-url')
}
stages {
stage('Build and Push Docker Image') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'gitlab-reg-log', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
container('kaniko') {
def imageWithTag = "${env.DOCKER_REGISTRY}/${env.IMAGE_NAME}:${env.BRANCH_NAME.replace('/', '-')}"
sh """
echo '{ "auths": { "${env.DOCKER_REGISTRY}": { "username": "${env.DOCKER_USERNAME}", "password": "${env.DOCKER_PASSWORD}" } } }' > /kaniko/.docker/config.json
"""
sh """
/kaniko/executor --context=${WORKSPACE} --dockerfile=${WORKSPACE}/Dockerfile --destination=${imageWithTag} --build-arg API_URL=${env.API_URL} --cache=true
"""
}
}
}
}
}
}
}