@@ -11,7 +11,6 @@ pipeline {
11
11
ansiColor(' xterm' )
12
12
buildDiscarder(logRotator(artifactNumToKeepStr : ' 1' ))
13
13
parallelsAlwaysFailFast()
14
- retry(1 )
15
14
skipStagesAfterUnstable()
16
15
timeout(time : 60 , unit : ' MINUTES' )
17
16
timestamps()
@@ -22,37 +21,100 @@ pipeline {
22
21
}
23
22
24
23
stages {
25
- stage(' Clean workspace' ) {
26
- options {
27
- timeout(time : 5 , unit : ' MINUTES' )
28
- }
24
+ stage(' Wait for blocking jobs' ) {
29
25
steps {
30
- cleanWs deleteDirs : true , patterns : [
31
- [pattern : ' packages' , type : ' INCLUDE' ],
32
- [pattern : ' global-packages' , type : ' INCLUDE' ],
33
- [pattern : ' tmp/NuGetScratch' , type : ' INCLUDE' ],
34
- [pattern : ' http-cache' , type : ' INCLUDE' ],
35
- [pattern : ' plugins-cache' , type : ' INCLUDE' ],
36
- [pattern : ' **/obj' , type : ' INCLUDE' ],
37
- [pattern : ' **/bin' , type : ' INCLUDE' ]
38
- ]
39
- }
40
- }
41
- stage(' Compile' ) {
26
+ script {
27
+ properties([[$class : ' BuildBlockerProperty' , blockLevel : ' GLOBAL' , blockingJobs : " .*/itextcore/${ env.JOB_BASE_NAME} " , scanQueueFor : ' ALL' , useBuildBlocker : true ]])
28
+ }
29
+ }
30
+ }
31
+ stage(' Build' ) {
42
32
options {
43
- timeout( time : 20 , unit : ' MINUTES ' )
33
+ retry( 2 )
44
34
}
45
- steps {
46
- 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} " ]) {
47
- bat " \" ${ env.NuGet} \" restore itext.html2pdf.sln"
48
- bat " dotnet restore itext.html2pdf.sln"
49
- bat " dotnet build itext.html2pdf.sln --configuration Release --source ${ env.WORKSPACE} /packages"
50
- script {
51
- createPackAllFile(findFiles(glob : ' **/*.nuspec' ))
52
- load ' packAll.groovy'
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
+ }
53
107
}
54
108
}
55
109
}
110
+ post {
111
+ failure {
112
+ sleep time : 2 , unit : ' MINUTES'
113
+ }
114
+ success {
115
+ script { currentBuild. result = ' SUCCESS' }
116
+ }
117
+ }
56
118
}
57
119
stage(' Run Tests' ) {
58
120
options {
@@ -83,15 +145,40 @@ pipeline {
83
145
script {
84
146
getAndConfigureJFrogCLI()
85
147
findFiles(glob : ' *.nupkg' ). each { item ->
86
- upload(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} "
87
151
}
88
152
}
89
153
}
90
154
}
91
- stage(' Archive Artifacts ' ) {
155
+ stage(' Branch Artifactory Deploy ' ) {
92
156
options {
93
157
timeout(time : 5 , unit : ' MINUTES' )
94
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
+ }
95
182
steps {
96
183
archiveArtifacts allowEmptyArchive : true , artifacts : ' *.nupkg'
97
184
}
@@ -133,6 +220,58 @@ pipeline {
133
220
134
221
}
135
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
+
136
275
@NonCPS // has to be NonCPS or the build breaks on the call to .each
137
276
def createPackAllFile (list ) {
138
277
// creates file because the bat command brakes the loop
@@ -170,11 +309,3 @@ def createRunTestCsProjsFile(list) {
170
309
writeFile file : ' runTestCsProjs.groovy' , text : cmd
171
310
}
172
311
173
- @NonCPS
174
- def upload (item ) {
175
- def itemArray = (item =~ / (.*?)(\. [0-9]*\. [0-9]*\. [0-9]*(-SNAPSHOT)?\. nupkg)/ )
176
- def dir = itemArray[ 0 ][ 1 ]
177
- sh " ./jfrog rt u \" ${ item.path} \" nuget/${ dir} / --flat=false --build-name=" ${env. BRANCH_NAME }" --build-number=${ env.BUILD_NUMBER} "
178
- }
179
-
180
-
0 commit comments