forked from Catrobat/Catroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.baseDocker
73 lines (63 loc) · 2.38 KB
/
Jenkinsfile.baseDocker
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
73
#!groovy
pipeline {
agent {
label 'LimitedEmulator'
}
environment {
DOCKERFILE = 'Dockerfile.jenkins'
DOCKER_DIR = 'docker'
DOCKER_REPO = "catrobat"
}
options {
timeout(time: 2, unit: 'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr: '30'))
}
triggers {
cron(env.BRANCH_NAME == 'develop' ? '@midnight' : '')
}
stages {
stage('Build docker image') {
steps {
// Build docker image
// Use --pull to force pull base docker image
// Use --force-rm and --no-cache to remove intermediate images and not use cache
sh '''#!/bin/bash
BUILD_ARGS="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --build-arg KVM_GROUP_ID=$(getent group kvm | cut -d: -f3)"
docker build --pull --force-rm --no-cache -t ${IMAGE_NAME} $BUILD_ARGS -f $DOCKER_DIR/$DOCKERFILE $DOCKER_DIR
'''
}
}
stage('Tag and push docker image') {
steps {
script {
// Push image to dockerhub use credentials
withCredentials([usernamePassword(credentialsId: 'catrobat-dockerhub', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
}
// Tag image with YearMonthDay+BuildNumber
sh 'docker tag ${IMAGE_NAME} $DOCKER_REPO/${IMAGE_NAME}:$(date +%Y%m%d).${BUILD_NUMBER}'
sh 'docker push $DOCKER_REPO/${IMAGE_NAME}:$(date +%Y%m%d).${BUILD_NUMBER}'
if (env.TAG_STABLE?.toBoolean()) {
sh 'docker tag ${IMAGE_NAME} $DOCKER_REPO/${IMAGE_NAME}:stable'
sh 'docker push $DOCKER_REPO/${IMAGE_NAME}:stable'
}
if (env.TAG_TESTING?.toBoolean()) {
sh 'docker tag ${IMAGE_NAME} $DOCKER_REPO/${IMAGE_NAME}:testing'
sh 'docker push $DOCKER_REPO/${IMAGE_NAME}:testing'
}
}
}
}
}
post {
always {
sh 'docker logout'
}
changed {
node('master') {
notifyChat()
}
}
}
}