-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
129 lines (116 loc) · 4.33 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!groovy
import groovy.json.JsonOutput
import hudson.Util;
pipeline {
agent any
triggers {
pollSCM('H/5 * * * *') //polling for changes, here every 5 min
}
stages {
stage("Setup") {
steps {
script {
env.GIT_COMMIT_MSG = sh (script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true).trim()
env.GIT_REPO_NAME = env.GIT_URL.replaceFirst(/^.*\/([^\/]+?).git$/, '$1')
env.REMOTE_DIR = "inthelifeofdoug.com/LudumDareBuilds/${env.GIT_REPO_NAME}/${env.BRANCH_NAME}/${BUILD_NUMBER}"
mqttNotification brokerUrl: 'tcp://home.inthelifeofdoug.com:1883',
credentialsId: 'mqttcreds',
message: getBeginMessage(),
qos: '2',
topic: "jenkins/${env.GIT_REPO_NAME}"
}
}
}
stage("Build Sprites") {
steps{
sh './gradlew clean'
sh './gradlew lwjgl3:sprites'
}
}
stage("Build Desktop") {
steps {
script {
sh './gradlew lwjgl3:jar'
}
}
}
stage("Build HTML") {
steps {
script {
sh './gradlew html:dist'
}
}
}
stage("Upload to Host") {
steps{
script {
sshPublisher(
publishers: [
sshPublisherDesc(
configName: "wxpick",
verbose: true,
transfers: [
sshTransfer(
sourceFiles: "html/build/dist/**",
removePrefix: "html/build/dist/",
remoteDirectory: "${env.REMOTE_DIR}",
)
])
])
}
}
}
}
post{
always {
mqttNotification brokerUrl: 'tcp://home.inthelifeofdoug.com:1883',
credentialsId: 'mqttcreds',
message: getMessage(),
qos: '2',
topic: "jenkins/${env.GIT_REPO_NAME}"
}
}
}
def getMessageAttrib() {
def changes = []
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
def files = new ArrayList(entry.affectedFiles)
echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
def commit = [commitId: "${entry.commitId}", author: "${entry.author}", message: "${entry.msg}", fileCount: "${files.size()}"]
commit.files = [];
for (int k = 0; k < files.size(); k++) {
def file = files[k]
echo " ${file.editType.name} ${file.path}"
commit.files << "${file.editType.name} ${file.path}"
}
changes << commit
}
}
def message = [
buildnumber: "${BUILD_NUMBER}",
status: "${currentBuild.currentResult}",
title: "${env.GIT_REPO_NAME}",
project: "${currentBuild.projectName}",
duration: "${Util.getTimeSpanString(System.currentTimeMillis() - currentBuild.startTimeInMillis)}",
commitmessage: "${env.GIT_COMMIT_MSG}",
buildURL: "${env.BUILD_URL}",
changesets: changes
]
return message
}
def getBeginMessage() {
def message = getMessageAttrib()
message.status = "STARTING"
return JsonOutput.prettyPrint(JsonOutput.toJson(message))
}
def getMessage() {
def message = getMessageAttrib()
if (currentBuild.resultIsBetterOrEqualTo("SUCCESS")) {
message.link = "http://${env.REMOTE_DIR}"
}
return JsonOutput.prettyPrint(JsonOutput.toJson(message))
}