-
Notifications
You must be signed in to change notification settings - Fork 37
/
Jenkinsfile
80 lines (78 loc) · 4.31 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
registry="romancin/rclonebrowser"
podTemplate(label: 'github-docker-builder', cloud: 'kubernetes',
containers: [
containerTemplate(name: 'buildkit', image: 'moby/buildkit:master', ttyEnabled: true, privileged: true),
containerTemplate(name: 'docker-readme', image: 'sheogorath/readme-to-dockerhub', command: 'sleep', args: '99d'),
],
volumes: [
secretVolume(secretName: 'docker-config', mountPath: '/root/.docker')
]) {
node('github-docker-builder') {
stage('Cloning Git Repository') {
container('buildkit') {
git url: 'https://github.com/romancin/rclonebrowser-docker.git',
branch: '$BRANCH_NAME'
}
}
stage('Building image and pushing it to the registry (develop)') {
if (env.BRANCH_NAME == 'develop') {
def gitbranch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
def version = readFile('VERSION')
def versions = version.split('\\.')
def major = gitbranch + '-' + versions[0]
def minor = gitbranch + '-' + versions[0] + '.' + versions[1]
def patch = gitbranch + '-' + version.trim()
container('buildkit') {
sh """
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${gitbranch},push=true
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${major},push=true
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${minor},push=true
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${patch},push=true
"""
}
}
}
stage('Building image and pushing it to the registry (main)') {
if (env.BRANCH_NAME == 'main') {
def gitbranch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
def version = readFile('VERSION')
def versions = version.split('\\.')
def major = versions[0]
def minor = versions[0] + '.' + versions[1]
def patch = version.trim()
container('buildkit') {
sh """
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:latest,push=true
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${major},push=true
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${minor},push=true
buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${registry}:${patch},push=true
"""
}
container('docker-readme') {
withEnv(['DOCKERHUB_REPO_NAME=tinymediamanager']) {
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKERHUB_PASSWORD', usernameVariable: 'DOCKERHUB_USERNAME')]) {
sh """
export DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME}
export DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD}
rm -rf /data && ln -s `pwd` /data
cd /data && node --unhandled-rejections=strict /app/index.js
"""
}
}
}
}
}
stage('Notify Build Result') {
withCredentials([string(credentialsId: 'discord-webhook-notificaciones', variable: 'DISCORD_WEBHOOK')]) {
discordSend description: "[Jenkins] - Pipeline CI-docker-rclonebrowser", footer: "", link: env.BUILD_URL, result: currentBuild.currentResult, title: JOB_NAME, webhookURL: "${DISCORD_WEBHOOK}"
}
}
}
}
properties([[
$class: 'BuildDiscarderProperty',
strategy: [
$class: 'LogRotator',
artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10']
]
]);