|
1 | 1 | #!/usr/bin/env groovy |
2 | 2 | @Library('pipeline-library')_ |
3 | 3 |
|
4 | | -def schedule = env.BRANCH_NAME.contains('master') ? '@monthly' : env.BRANCH_NAME == 'develop' ? '@midnight' : '' |
5 | | - |
6 | | -pipeline { |
7 | | - |
8 | | - agent { label 'windows' } |
9 | | - |
10 | | - options { |
11 | | - ansiColor('xterm') |
12 | | - buildDiscarder(logRotator(artifactNumToKeepStr: '1')) |
13 | | - parallelsAlwaysFailFast() |
14 | | - skipStagesAfterUnstable() |
15 | | - timeout(time: 60, unit: 'MINUTES') |
16 | | - timestamps() |
17 | | - } |
18 | | - |
19 | | - triggers { |
20 | | - cron(schedule) |
21 | | - } |
22 | | - |
23 | | - stages { |
24 | | - stage('Wait for blocking jobs') { |
25 | | - steps { |
26 | | - script { |
27 | | - properties([[$class: 'BuildBlockerProperty', blockLevel: 'GLOBAL', blockingJobs: ".*/itextcore/${env.JOB_BASE_NAME}", scanQueueFor: 'ALL', useBuildBlocker: true]]) |
28 | | - } |
29 | | - } |
30 | | - } |
31 | | - stage('Build') { |
32 | | - options { |
33 | | - retry(2) |
34 | | - } |
35 | | - stages { |
36 | | - stage('Clean workspace') { |
37 | | - options { |
38 | | - timeout(time: 5, unit: 'MINUTES') |
39 | | - } |
40 | | - steps { |
41 | | - cleanWs deleteDirs: true, patterns: [ |
42 | | - [pattern: 'packages', type: 'INCLUDE'], |
43 | | - [pattern: 'global-packages', type: 'INCLUDE'], |
44 | | - [pattern: 'tmp/NuGetScratch', type: 'INCLUDE'], |
45 | | - [pattern: 'http-cache', type: 'INCLUDE'], |
46 | | - [pattern: 'plugins-cache', type: 'INCLUDE'], |
47 | | - [pattern: '**/obj', type: 'INCLUDE'], |
48 | | - [pattern: '**/bin', type: 'INCLUDE'], |
49 | | - [pattern: '**/*.nupkg', type: 'INCLUDE'] |
50 | | - ] |
51 | | - } |
52 | | - } |
53 | | - stage('Install branch dependencies') { |
54 | | - options { |
55 | | - timeout(time: 5, unit: 'MINUTES') |
56 | | - } |
57 | | - when { |
58 | | - not { |
59 | | - anyOf { |
60 | | - branch "master" |
61 | | - branch "develop" |
62 | | - } |
63 | | - } |
64 | | - } |
65 | | - steps { |
66 | | - script { |
67 | | - getAndConfigureJFrogCLI() |
68 | | - sh "./jfrog rt dl --flat=true branch-artifacts/${env.JOB_BASE_NAME}/**/dotnet/" |
69 | | - // create global-packages directory |
70 | | - dir("${env.WORKSPACE}/global-packages") {writeFile file:'dummy', text:''} |
71 | | - nuspecFiles = findFiles(glob: '**/*.nuspec') |
72 | | - buildArtifacts = [] |
73 | | - nuspecFiles.each{ nuspecFile -> |
74 | | - def xmlTxt = sh(returnStdout: true, script: '#!/bin/sh -e\n' + "cat \"${nuspecFile.path.replace('\\','/')}\"").replaceAll("^.*<", "<") |
75 | | - def xml = new XmlSlurper(false, false).parseText("${xmlTxt}") |
76 | | - def artifactId = "${xml.metadata.id}" |
77 | | - def artifactVersion = "${xml.metadata.version}" |
78 | | - artifact = "${artifactId}.${artifactVersion}" |
79 | | - buildArtifacts.add(artifact) |
80 | | - } |
81 | | - withEnv(["NUGET_PACKAGES=${env.WORKSPACE}/global-packages", "temp=${env.WORKSPACE}/tmp/NuGetScratch", "NUGET_HTTP_CACHE_PATH=${env.WORKSPACE}/http-cache", "NUGET_PLUGINS_CACHE_PATH=${env.WORKSPACE}/plugins-cache", "gsExec=${gsExec}", "compareExec=${compareExec}"]) { |
82 | | - createInstallAllFile(findFiles(glob: '**/*.nupkg'), buildArtifacts) |
83 | | - load 'installAll.groovy' |
84 | | - } |
85 | | - nupkgFiles = findFiles(glob: '*.nupkg') |
86 | | - nupkgFiles.each{ nupkgFile -> |
87 | | - println "Delete downloaded ${nupkgFile.path}" |
88 | | - cleanWs deleteDirs: true, patterns: [[pattern: "${nupkgFile.path}", type: 'INCLUDE']] |
89 | | - } |
90 | | - } |
91 | | - } |
92 | | - } |
93 | | - stage('Compile') { |
94 | | - options { |
95 | | - timeout(time: 20, unit: 'MINUTES') |
96 | | - } |
97 | | - steps { |
98 | | - withEnv(["NUGET_PACKAGES=${env.WORKSPACE}/global-packages", "temp=${env.WORKSPACE}/tmp/NuGetScratch", "NUGET_HTTP_CACHE_PATH=${env.WORKSPACE}/http-cache", "NUGET_PLUGINS_CACHE_PATH=${env.WORKSPACE}/plugins-cache", "gsExec=${gsExec}", "compareExec=${compareExec}"]) { |
99 | | - bat "\"${env.NuGet}\" restore itext.html2pdf.sln" |
100 | | - bat "dotnet restore itext.html2pdf.sln" |
101 | | - bat "dotnet build itext.html2pdf.sln --configuration Release --source ${env.WORKSPACE}/packages" |
102 | | - script { |
103 | | - createPackAllFile(findFiles(glob: '**/*.nuspec')) |
104 | | - load 'packAll.groovy' |
105 | | - } |
106 | | - } |
107 | | - } |
108 | | - } |
109 | | - } |
110 | | - post { |
111 | | - failure { |
112 | | - sleep time: 2, unit: 'MINUTES' |
113 | | - } |
114 | | - success { |
115 | | - script { currentBuild.result = 'SUCCESS' } |
116 | | - } |
117 | | - } |
118 | | - } |
119 | | - stage('Run Tests') { |
120 | | - options { |
121 | | - timeout(time: 60, unit: 'MINUTES') |
122 | | - } |
123 | | - steps { |
124 | | - withEnv(["NUGET_PACKAGES=${env.WORKSPACE}/global-packages", "temp=${env.WORKSPACE}/tmp/NuGetScratch", "NUGET_HTTP_CACHE_PATH=${env.WORKSPACE}/http-cache", "NUGET_PLUGINS_CACHE_PATH=${env.WORKSPACE}/plugins-cache", "gsExec=${gsExec}", "compareExec=${compareExec}"]) { |
125 | | - script { |
126 | | - createRunTestDllsFile(findFiles(glob: '**/itext.*.tests.dll')) |
127 | | - load 'runTestDlls.groovy' |
128 | | - createRunTestCsProjsFile(findFiles(glob: '**/itext.*.tests.netstandard.csproj')) |
129 | | - load 'runTestCsProjs.groovy' |
130 | | - } |
131 | | - } |
132 | | - } |
133 | | - } |
134 | | - stage('Artifactory Deploy') { |
135 | | - options { |
136 | | - timeout(time: 5, unit: 'MINUTES') |
137 | | - } |
138 | | - when { |
139 | | - anyOf { |
140 | | - branch "master" |
141 | | - branch "develop" |
142 | | - } |
143 | | - } |
144 | | - steps { |
145 | | - script { |
146 | | - getAndConfigureJFrogCLI() |
147 | | - findFiles(glob: '*.nupkg').each { item -> |
148 | | - def itemArray = (item =~ /(.*?)(\.[0-9]*\.[0-9]*\.[0-9]*(-SNAPSHOT)?)/) |
149 | | - def dir = itemArray[ 0 ][ 1 ] |
150 | | - sh "./jfrog rt u \"${item.path}\" nuget/${dir}/ --flat=false --build-name ${env.BRANCH_NAME} --build-number ${env.BUILD_NUMBER}" |
151 | | - } |
152 | | - } |
153 | | - } |
154 | | - } |
155 | | - stage('Branch Artifactory Deploy') { |
156 | | - options { |
157 | | - timeout(time: 5, unit: 'MINUTES') |
158 | | - } |
159 | | - when { |
160 | | - not { |
161 | | - anyOf { |
162 | | - branch "master" |
163 | | - branch "develop" |
164 | | - } |
165 | | - } |
166 | | - } |
167 | | - steps { |
168 | | - script { |
169 | | - if (env.GIT_URL) { |
170 | | - repoName = ("${env.GIT_URL}" =~ /(.*\/)(.*)(\.git)/)[ 0 ][ 2 ] |
171 | | - findFiles(glob: '*.nupkg').each { item -> |
172 | | - sh "./jfrog rt u \"${item.path}\" branch-artifacts/${env.BRANCH_NAME}/${repoName}/dotnet/ --recursive=false --build-name ${env.BRANCH_NAME} --build-number ${env.BUILD_NUMBER} --props \"vcs.revision=${env.GIT_COMMIT};repo.name=${repoName}\"" |
173 | | - } |
174 | | - } |
175 | | - } |
176 | | - } |
177 | | - } |
178 | | - stage('Archive Artifacts') { |
179 | | - options { |
180 | | - timeout(time: 5, unit: 'MINUTES') |
181 | | - } |
182 | | - steps { |
183 | | - archiveArtifacts allowEmptyArchive: true, artifacts: '*.nupkg' |
184 | | - } |
185 | | - } |
186 | | - } |
187 | | - |
188 | | - post { |
189 | | - always { |
190 | | - echo 'One way or another, I have finished \uD83E\uDD16' |
191 | | - } |
192 | | - success { |
193 | | - echo 'I succeeeded! \u263A' |
194 | | - cleanWs deleteDirs: true |
195 | | - } |
196 | | - unstable { |
197 | | - echo 'I am unstable \uD83D\uDE2E' |
198 | | - } |
199 | | - failure { |
200 | | - echo 'I failed \uD83D\uDCA9' |
201 | | - } |
202 | | - changed { |
203 | | - echo 'Things were different before... \uD83E\uDD14' |
204 | | - } |
205 | | - fixed { |
206 | | - script { |
207 | | - if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == 'develop')) { |
208 | | - slackNotifier("#ci", currentBuild.currentResult, "${env.BRANCH_NAME} - Back to normal") |
209 | | - } |
210 | | - } |
211 | | - } |
212 | | - regression { |
213 | | - script { |
214 | | - if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == 'develop')) { |
215 | | - slackNotifier("#ci", currentBuild.currentResult, "${env.BRANCH_NAME} - First failure") |
216 | | - } |
217 | | - } |
218 | | - } |
219 | | - } |
220 | | - |
221 | | -} |
222 | | - |
223 | | -@NonCPS // has to be NonCPS or the build breaks on the call to .each |
224 | | -def createInstallAllFile(list, buildArtifacts) { |
225 | | - // creates file because the sh command brakes the loop |
226 | | - def buildArtifactsList = buildArtifacts.join(",") |
227 | | - def ws = "${env.WORKSPACE.replace('\\','/')}" |
228 | | - def cmd = "import groovy.xml.XmlUtil\n" |
229 | | - cmd = cmd + "def xmlTxt = ''\n" |
230 | | - cmd = cmd + "def buildArtifacts = \"${buildArtifactsList}\".split(',').collect{it as java.lang.String}\n" |
231 | | - list.each { item -> |
232 | | - filename = item.getName() |
233 | | - def itemArray = (item.getName() =~ /(.*?)\.([0-9]*)\.([0-9]*)\.([0-9]*)(|-SNAPSHOT)/) |
234 | | - def name = itemArray[0][1] |
235 | | - if (!buildArtifacts.contains("${filename.replace(".nupkg","")}")) { |
236 | | - cmd = cmd + "try {xmlTxt = sh(returnStdout: true, script: 'unzip -p ${filename} ${name}.nuspec')} catch (Exception err) { }\n" |
237 | | - cmd = cmd + "xmlTxt = \"\${xmlTxt.replaceFirst('.*?<?xml version','<?xml version')}\"\n" |
238 | | - cmd = cmd + "xml = new XmlSlurper(false, false).parseText(xmlTxt)\n" |
239 | | - cmd = cmd + "install = true\n" |
240 | | - cmd = cmd + "xml.metadata.dependencies.group.dependency.each { dependency ->\n" |
241 | | - cmd = cmd + " artifact = \"\${dependency[\'@id\']}.\${dependency[\'@version\']}\".toString()\n" |
242 | | - cmd = cmd + " if (buildArtifacts.contains(artifact)) {\n" |
243 | | - cmd = cmd + " install = false\n" |
244 | | - cmd = cmd + " }\n" |
245 | | - cmd = cmd + "}\n" |
246 | | - cmd = cmd + "xml.metadata.dependencies.dependency.each { dependency ->\n" |
247 | | - cmd = cmd + " artifact = \"\${dependency[\'@id\']}.\${dependency[\'@version\']}\".toString()\n" |
248 | | - cmd = cmd + " if (buildArtifacts.contains(artifact)) {\n" |
249 | | - cmd = cmd + " install = false\n" |
250 | | - cmd = cmd + " }\n" |
251 | | - cmd = cmd + "}\n" |
252 | | - cmd = cmd + "if (install) {\n" |
253 | | - cmd = cmd + " xml.metadata.dependencies.group.dependency.each { dependency ->\n" |
254 | | - cmd = cmd + " if (\"\${dependency[\'@id\']}\".contains(\"itext7\")) {\n" |
255 | | - cmd = cmd + " sh \"${env.NuGet.replace('\\','/')} install \${dependency[\'@id\']} -PreRelease -Version \${dependency[\'@version\']} -OutputDirectory packages -Source '${ws};https://repo.itextsupport.com/api/nuget/nuget;https://api.nuget.org/v3/index.json'\"\n" |
256 | | - cmd = cmd + " }\n" |
257 | | - cmd = cmd + " }\n" |
258 | | - cmd = cmd + " xml.metadata.dependencies.dependency.each { dependency ->\n" |
259 | | - cmd = cmd + " if (\"\${dependency[\'@id\']}\".contains(\"itext7\")) {\n" |
260 | | - cmd = cmd + " sh \"${env.NuGet.replace('\\','/')} install \${dependency[\'@id\']} -PreRelease -Version \${dependency[\'@version\']} -OutputDirectory packages -Source '${ws};https://repo.itextsupport.com/api/nuget/nuget;https://api.nuget.org/v3/index.json'\"\n" |
261 | | - cmd = cmd + " }\n" |
262 | | - cmd = cmd + " }\n" |
263 | | - cmd = cmd + " try {sh 'rm -r ${ws}/global-packages/${name}'} catch (Exception err) { }\n" |
264 | | - cmd = cmd + " try {sh 'rm -r ${ws}/packages/${filename.replace('.nupkg','')}'} catch (Exception err) { }\n" |
265 | | - cmd = cmd + " sh '\"${env.NuGet.replace('\\','/')}\" install ${name} -PreRelease -OutputDirectory packages -Source \"${ws};https://api.nuget.org/v3/index.json\"'\n" |
266 | | - cmd = cmd + " sh '\"${env.NuGet.replace('\\','/')}\" push ${ws}/${filename} -Source \"${ws}/global-packages\"'\n" |
267 | | - cmd = cmd + "} else {\n" |
268 | | - cmd = cmd + " println \"Not installing '${filename}' - this repository will build dependencies for it....\"\n" |
269 | | - cmd = cmd + "}\n" |
270 | | - } |
271 | | - } |
272 | | - writeFile file: 'installAll.groovy', text: cmd |
273 | | -} |
274 | | - |
275 | | -@NonCPS // has to be NonCPS or the build breaks on the call to .each |
276 | | -def createPackAllFile(list) { |
277 | | - // creates file because the bat command brakes the loop |
278 | | - def cmd = '' |
279 | | - list.each { item -> |
280 | | - if (!item.path.contains("packages")) { |
281 | | - cmd = cmd + "bat '\"${env.NuGet.replace('\\','\\\\')}\" pack \"${item.path.replace('\\','\\\\')}\"'\n" |
282 | | - } |
283 | | - } |
284 | | - writeFile file: 'packAll.groovy', text: cmd |
285 | | -} |
286 | | - |
287 | | -@NonCPS // has to be NonCPS or the build breaks on the call to .each |
288 | | -def createRunTestDllsFile(list) { |
289 | | - // creates file because the bat command brakes the loop |
290 | | - def ws = "${env.WORKSPACE.replace('\\','\\\\')}" |
291 | | - def nunit = "${env.'Nunit3-console'.replace('\\','\\\\')}" |
292 | | - def cmd = '' |
293 | | - list.each { item -> |
294 | | - if (!item.path.contains("netcoreapp1.0") && !item.path.contains("obj")) { |
295 | | - cmd = cmd + "bat '\"${nunit}\" \"${ws}\\\\${item.path.replace('\\','\\\\')}\" --result=${item.name}-TestResult.xml'\n" |
296 | | - } |
297 | | - } |
298 | | - writeFile file: 'runTestDlls.groovy', text: cmd |
299 | | -} |
300 | | - |
301 | | -@NonCPS // has to be NonCPS or the build breaks on the call to .each |
302 | | -def createRunTestCsProjsFile(list) { |
303 | | - // creates file because the bat command brakes the loop |
304 | | - def ws = "${env.WORKSPACE.replace('\\','\\\\')}" |
305 | | - def cmd = '' |
306 | | - list.each { item -> |
307 | | - cmd = cmd + "bat 'dotnet test ${ws}\\\\${item.path.replace('\\','\\\\')} --framework netcoreapp1.0 --configuration Release --no-build --logger \"trx;LogFileName=results.trx\"'\n" |
308 | | - } |
309 | | - writeFile file: 'runTestCsProjs.groovy', text: cmd |
310 | | -} |
| 4 | +def repoName = "pdfHtml" |
| 5 | +def dependencyRegex = "itextcore" |
| 6 | +def solutionFile = "itext.html2pdf.sln" |
311 | 7 |
|
| 8 | +automaticDotnetBuild(repoName, dependencyRegex, solutionFile) |
0 commit comments