-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
80 lines (76 loc) · 2.25 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
pipeline {
environment {
userName = "hexlo"
imageName = "minecraft-bedrock-server"
tag = 'latest'
gitRepo = "https://github.com/${userName}/${imageName}.git"
dockerhubRegistry = "${userName}/${imageName}"
githubRegistry = "ghcr.io/${userName}/${imageName}"
dockerhubCredentials = 'DOCKERHUB_TOKEN'
githubCredentials = 'GITHUB_TOKEN'
dockerhubImage = ''
githubImage = ''
serverVersion = ''
}
agent any
stages {
stage('Cloning Git') {
steps {
git branch: 'main', credentialsId: "${githubCredentials}", url: "${gitRepo}"
}
}
stage('Getting Latest Version') {
steps {
script {
if (tag == 'latest') {
serverVersion = sh(script: "${WORKSPACE}/.scripts/get-latest-version.sh", , returnStdout: true).trim()
}
else {
serverVersion = tag
}
echo "serverVersion=${serverVersion}"
}
}
}
stage('Building image') {
steps{
script {
// Docker Hub
dockerhubImage = docker.build( "${dockerhubRegistry}:${tag}", "--no-cache .")
// Github
githubImage = docker.build( "${githubRegistry}:${tag}", "--no-cache .")
}
}
}
stage('Deploy Image') {
steps{
script {
// Docker Hub
docker.withRegistry( '', "${dockerhubCredentials}" ) {
dockerhubImage.push("${tag}")
dockerhubImage.push("${serverVersion}")
}
// Github
docker.withRegistry("https://${githubRegistry}", "${githubCredentials}" ) {
githubImage.push("${tag}")
githubImage.push("${serverVersion}")
}
}
}
}
stage('Remove Unused docker images') {
steps{
sh "docker system prune -f"
}
}
}
post {
failure {
mail bcc: '', body: "<b>Jenkins Build Report</b><br><br> Project: ${env.JOB_NAME} <br> \
Build Number: ${env.BUILD_NUMBER} <br> \
Status: <b>Failed</b> <br> \
Build URL: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', \
subject: "Jenkins Build Failed: ${env.JOB_NAME}", to: "[email protected]";
}
}
}