-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
122 lines (111 loc) · 5.26 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
#!/usr/bin/env groovy
import groovy.json.JsonOutput
// Has to be the same as the solution name!
def modName = 'Bookcase'
// Needed to map jenkins config and nuget store to the container
def jenkinsHome = "/var/lib/jenkins"
// Path to the game, needed for build, mapped to /pot/stardewvalley in the csproj file
def gamePath = "/opt/stardewvalley"
pipeline {
agent {
docker {
image 'mono:6.12.0.107'
args "-v $gamePath:/opt/stardewvalley -v $jenkinsHome/.config/:/.config/:rw,z -v $jenkinsHome/.nuget/:/.nuget/:rw,z"
}
}
stages {
stage("Clean") {
steps {
script {
println 'Cleaning build directory'
sh(script: "rm -rf build/")
}
}
}
stage("Preflight") {
steps {
script {
println 'Starting preflight'
sh(script: "sed -i 's/%build_number%/$env.BUILD_NUMBER/g' build.json")
def buildConfig = readJSON file: "build.json"
def version = buildConfig["version"]
sh(script: "sed -i 's/1\\.0\\.0-no-op/$version/g' '$modName/manifest.json'")
}
}
}
stage('Build') {
steps {
echo 'Building'
sh "nuget restore '${modName}.sln'"
sh "msbuild -p:EnableModDeploy=false -p:GamePath=$gamePath -p:ModZipPath=../build/"
}
}
stage('Deploy') {
steps {
withCredentials([file(credentialsId: 'mod_build_secrets', variable: 'SECRET_FILE')]) {
script {
final String url = "https://stardewvalley.curseforge.com"
def manifest = [
changelog : "",
changelogType: "",
displayName : "",
gameVersions : [],
releaseType : ""
]
def buildConfig = readJSON file: "build.json"
if (buildConfig.containsKey("relations") && buildConfig['relations'].size() > 0) {
manifest = [
changelog : "",
changelogType: "",
displayName : "",
gameVersions : [],
releaseType : "",
relations : [
projects: []
]
]
}
def deploy = buildConfig["deploy"]
if (deploy) {
manifest["changelog"] = readFile(file: buildConfig["changelogFile"])
manifest['changelogType'] = buildConfig["changelogType"]
manifest["releaseType"] = buildConfig["releaseType"]
if (buildConfig.containsKey("relations") && buildConfig['relations'].size() > 0)
manifest["relations"]["projects"] = buildConfig['relations']
def secrets = readJSON file: SECRET_FILE
def projectId = buildConfig["curseProjectId"];
def gameVersions = buildConfig["gameVersions"];
def curseApiKey = secrets["curseApiKey"]
final String versionRequest = sh(script: "set +x && curl -s $url/api/game/versions -H 'X-Api-Token: $curseApiKey'", returnStdout: true).trim()
def versionList = readJSON text: versionRequest
def curseVersions = versionList.findAll {
for (String version : gameVersions) {
if (it.name == version) {
return true;
}
}
}.collect {
it.id
};
println "Found curse versions: $curseVersions"
manifest.gameVersions = curseVersions;
final String fileName = sh(script: "ls build/", returnStdout: true).trim()
manifest["displayName"] = fileName
def json = JsonOutput.toJson(manifest)
println "Uploading"
final String response = sh(script: "set +x && curl -s $url/api/projects/$projectId/upload-file -H 'X-Api-Token: $curseApiKey' -H 'content-type: multipart/form-data;' --form 'metadata=$json' --form 'file=@build/$fileName'", returnStdout: true).trim()
println "Upload Complete"
} else {
println "Deploy disabled in build.json!"
}
}
}
}
}
}
post {
always {
archiveArtifacts 'build/**'
}
}
}