-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile
150 lines (109 loc) · 4.89 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env groovy
// This pipeline is designed to run on Esri-internal CI infrastructure.
@Library('psl')
import com.esri.zrh.jenkins.PipelineSupportLibrary
import com.esri.zrh.jenkins.PslFactory
import com.esri.zrh.jenkins.psl.UploadTrackingPsl
import com.esri.zrh.jenkins.JenkinsTools
import com.esri.zrh.jenkins.ToolInfo
import com.esri.zrh.jenkins.ce.CityEnginePipelineLibrary
import com.esri.zrh.jenkins.ce.PrtAppPipelineLibrary
import groovy.transform.Field
@Field def psl = PslFactory.create(this, UploadTrackingPsl.ID)
@Field def cepl = new CityEnginePipelineLibrary(this, psl)
@Field def papl = new PrtAppPipelineLibrary(cepl)
// -- PIPELINE SETUP
psl.runsHere('production')
env.PIPELINE_ARCHIVING_ALLOWED = "true"
properties([ disableConcurrentBuilds() ])
// -- CONFIGURATION
@Field final String REPO = 'git@github.com:esri/puma.git'
@Field final String SOURCE = 'puma.git'
@Field final String SOURCE_STASH = 'puma-sources'
@Field final String DOCKER_AGENT_WINDOWS = 'win19-64-d'
@Field final String DOCKER_WS_WINDOWS = "c:/temp/puma/ws"
@Field final Map WINDOWS_DOCKER_CONFIG = [ ba: DOCKER_AGENT_WINDOWS, ws: DOCKER_WS_WINDOWS ]
@Field final Map WINDOWS_NATIVE_CONFIG = [ os: cepl.CFG_OS_WIN10, bc: cepl.CFG_BC_REL, tc: cepl.CFG_TC_VC1437, cc: cepl.CFG_CC_OPT, arch: cepl.CFG_ARCH_X86_64 ]
@Field final Map RHINO7_CONFIG = [ rh: '7.17.22102.5001', rhsdk: '7.19.22165.13001', py: '3.9.13' ]
@Field final Map RHINO8_CONFIG = [ rh: '8.8.24163.12481', rhsdk: '8.8.24163.12481', py: '3.9.13' ]
@Field final int DOCKER_IMAGE_REVISION = 2 // see counter part in the containers repository
@Field final List CONFIGS_PREPARE = [
WINDOWS_NATIVE_CONFIG
]
@Field final List CONFIGS = [
composeConfig(RHINO7_CONFIG, WINDOWS_NATIVE_CONFIG, WINDOWS_DOCKER_CONFIG),
composeConfig(RHINO8_CONFIG, WINDOWS_NATIVE_CONFIG, WINDOWS_DOCKER_CONFIG),
]
// -- THE PIPELINE
stage('prepare') {
cepl.runParallel(taskGenPrepare())
}
stage('build') {
cepl.runParallel(taskGenPuma())
}
// -- TASK GENERATORS
Map taskGenPrepare() {
Map tasks = [:]
tasks << cepl.generateTasks('prepare', this.&taskPrepare, CONFIGS_PREPARE)
return tasks
}
Map taskGenPuma() {
return cepl.generateTasks('build', this.&taskBuildPuma, CONFIGS)
}
// -- TASK IMPLEMENTATIONS
def taskPrepare(cfg) {
cepl.cleanCurrentDir()
papl.checkout(REPO, env.BRANCH_NAME)
updateVersionProperties("${SOURCE}/version.properties", BUILD_ID)
stash(name: SOURCE_STASH)
}
def taskBuildPuma(cfg) {
cepl.cleanCurrentDir()
unstash(name: SOURCE_STASH)
final String tag = "rh${cfg.rh}-rhsdk${cfg.rhsdk}-py${cfg.py}-v${DOCKER_IMAGE_REVISION}"
final String image = "zrh-dreg-sp-1.esri.com/puma/puma-toolchain:${tag}"
final String buildCmd = "ci_build.cmd"
final String containerName = "puma-build-rh${cfg.rh}-${env.BRANCH_NAME.replaceAll('/', '_')}-b${BUILD_ID}"
String workDir = "${cfg.ws}/${SOURCE}"
Map dirMap = [ (env.WORKSPACE) : cfg.ws ]
final String rhinoMajorVersion = cfg.rh.tokenize('.')[0]
Map envMap = [ 'RHINO_VER_MAJOR' : rhinoMajorVersion, 'PUMA_VER_BUILD' : BUILD_ID ]
runDockerCmd(cfg, image, containerName, dirMap, envMap, workDir, buildCmd)
manifest = readYaml(file: "${SOURCE}/manifest.yml") // called within publish, different cwd
// build final package version as <major>.<minor>.<revision>.<build number>
final List pkgVerComponents = manifest.version.tokenize('.')
pkgVerComponents[3] = BUILD_ID
final String pkgVer = pkgVerComponents.join('.')
def getVersion = { return pkgVer }
def getClassifier = {
List rhVerComp = cfg.rh.tokenize('.')
return "rh${rhVerComp[0]}_${rhVerComp[1]}-win"
}
papl.publish('cityengine_for_rhino', env.BRANCH_NAME, '*.yak', getVersion, cfg, getClassifier, "${SOURCE}/packages")
papl.publish('cityengine_for_rhino', env.BRANCH_NAME, '*.rhi', getVersion, cfg, getClassifier, "${SOURCE}/packages")
}
// -- HELPERS
@NonCPS
Map composeConfig(rh, tc, dc) {
return rh + tc + dc + [ grp: "rh${rh['rh']}+rhsdk${rh['rhsdk']}" ]
}
def updateVersionProperties(String propFile, String buildId) {
def versionProps = readProperties(file: propFile)
versionProps.VERSION_BUILD = buildId
def propsText = versionProps.collect{ entry->entry.key+"="+entry.value }.join('\n')
writeFile(file: propFile, text: propsText)
}
def runDockerCmd(Map cfg, String image, String containerName, Map dirMap, Map envMap, String workDir, String cmd) {
String dirMapStrArgs = ""
dirMap.each { k,v -> dirMapStrArgs += " -v \"${k}:${v}\"" }
String envMapStrArgs = ''
envMap.each { k, v -> envMapStrArgs += " --env ${k}=${v}" }
String runArgs = '--pull always --rm'
runArgs += " --name ${containerName}"
runArgs += dirMapStrArgs
runArgs += " -w ${workDir}"
runArgs += envMapStrArgs
runArgs += " ${image}"
runArgs += isUnix() ? " bash -c '${cmd}'" : " cmd /c \"${cmd}\""
psl.runCmd("docker run ${runArgs}")
}