@@ -45,10 +45,51 @@ pipeline {
4545 [pattern : ' http-cache' , type : ' INCLUDE' ],
4646 [pattern : ' plugins-cache' , type : ' INCLUDE' ],
4747 [pattern : ' **/obj' , type : ' INCLUDE' ],
48- [pattern : ' **/bin' , type : ' INCLUDE' ]
48+ [pattern : ' **/bin' , type : ' INCLUDE' ],
49+ [pattern : ' **/*.nupkg' , type : ' INCLUDE' ]
4950 ]
5051 }
5152 }
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+ }
5293 stage(' Compile' ) {
5394 options {
5495 timeout(time : 20 , unit : ' MINUTES' )
@@ -102,17 +143,41 @@ pipeline {
102143 }
103144 steps {
104145 script {
105- getAndConfigureJFrogCLI()
106146 findFiles(glob : ' *.nupkg' ). each { item ->
107- upload(item)
147+ def itemArray = (item =~ / (.*?)(\. [0-9]*\. [0-9]*\. [0-9]*(-SNAPSHOT)?)/ )
148+ def dir = itemArray[ 0 ][ 1 ]
149+ sh " ./jfrog rt u \" ${ item.path} \" nuget/${ dir} / --flat=false --build-name ${ env.BRANCH_NAME} --build-number ${ env.BUILD_NUMBER} "
108150 }
109151 }
110152 }
111153 }
112- stage(' Archive Artifacts ' ) {
154+ stage(' Branch Artifactory Deploy ' ) {
113155 options {
114156 timeout(time : 5 , unit : ' MINUTES' )
115157 }
158+ when {
159+ not {
160+ anyOf {
161+ branch " master"
162+ branch " develop"
163+ }
164+ }
165+ }
166+ steps {
167+ script {
168+ if (env. GIT_URL ) {
169+ repoName = (" ${ env.GIT_URL} " =~ / (.*\/ )(.*)(\. git)/ )[ 0 ][ 2 ]
170+ findFiles(glob : ' *.nupkg' ). each { item ->
171+ 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} \" "
172+ }
173+ }
174+ }
175+ }
176+ }
177+ stage(' Archive Artifacts' ) {
178+ options {
179+ timeout(time : 5 , unit : ' MINUTES' )
180+ }
116181 steps {
117182 archiveArtifacts allowEmptyArchive : true , artifacts : ' *.nupkg'
118183 }
@@ -154,6 +219,58 @@ pipeline {
154219
155220}
156221
222+ @NonCPS // has to be NonCPS or the build breaks on the call to .each
223+ def createInstallAllFile (list , buildArtifacts ) {
224+ // creates file because the sh command brakes the loop
225+ def buildArtifactsList = buildArtifacts. join(" ," )
226+ def ws = " ${ env.WORKSPACE.replace('\\','/')} "
227+ def cmd = " import groovy.xml.XmlUtil\n "
228+ cmd = cmd + " def xmlTxt = ''\n "
229+ cmd = cmd + " def buildArtifacts = \" ${ buildArtifactsList} \" .split(',').collect{it as java.lang.String}\n "
230+ list. each { item ->
231+ filename = item. getName()
232+ def itemArray = (item. getName() =~ / (.*?)\. ([0-9]*)\. ([0-9]*)\. ([0-9]*)(|-SNAPSHOT)/ )
233+ def name = itemArray[0 ][1 ]
234+ if (! buildArtifacts. contains(" ${ filename.replace(".nupkg","")} " )) {
235+ cmd = cmd + " try {xmlTxt = sh(returnStdout: true, script: 'unzip -p ${ filename} ${ name} .nuspec')} catch (Exception err) { }\n "
236+ cmd = cmd + " xmlTxt = \"\$ {xmlTxt.replaceFirst('.*?<?xml version','<?xml version')}\"\n "
237+ cmd = cmd + " xml = new XmlSlurper(false, false).parseText(xmlTxt)\n "
238+ cmd = cmd + " install = true\n "
239+ cmd = cmd + " xml.metadata.dependencies.group.dependency.each { dependency ->\n "
240+ cmd = cmd + " artifact = \"\$ {dependency[\' @id\' ]}.\$ {dependency[\' @version\' ]}\" .toString()\n "
241+ cmd = cmd + " if (buildArtifacts.contains(artifact)) {\n "
242+ cmd = cmd + " install = false\n "
243+ cmd = cmd + " }\n "
244+ cmd = cmd + " }\n "
245+ cmd = cmd + " xml.metadata.dependencies.dependency.each { dependency ->\n "
246+ cmd = cmd + " artifact = \"\$ {dependency[\' @id\' ]}.\$ {dependency[\' @version\' ]}\" .toString()\n "
247+ cmd = cmd + " if (buildArtifacts.contains(artifact)) {\n "
248+ cmd = cmd + " install = false\n "
249+ cmd = cmd + " }\n "
250+ cmd = cmd + " }\n "
251+ cmd = cmd + " if (install) {\n "
252+ cmd = cmd + " xml.metadata.dependencies.group.dependency.each { dependency ->\n "
253+ cmd = cmd + " if (\"\$ {dependency[\' @id\' ]}\" .contains(\" itext7\" )) {\n "
254+ 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 "
255+ cmd = cmd + " }\n "
256+ cmd = cmd + " }\n "
257+ cmd = cmd + " xml.metadata.dependencies.dependency.each { dependency ->\n "
258+ cmd = cmd + " if (\"\$ {dependency[\' @id\' ]}\" .contains(\" itext7\" )) {\n "
259+ 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 "
260+ cmd = cmd + " }\n "
261+ cmd = cmd + " }\n "
262+ cmd = cmd + " try {sh 'rm -r ${ ws} /global-packages/${ name} '} catch (Exception err) { }\n "
263+ cmd = cmd + " try {sh 'rm -r ${ ws} /packages/${ filename.replace('.nupkg','')} '} catch (Exception err) { }\n "
264+ cmd = cmd + " sh '\" ${ env.NuGet.replace('\\','/')} \" install ${ name} -PreRelease -OutputDirectory packages -Source \" ${ ws} ;https://api.nuget.org/v3/index.json\" '\n "
265+ cmd = cmd + " sh '\" ${ env.NuGet.replace('\\','/')} \" push ${ ws} /${ filename} -Source \" ${ ws} /global-packages\" '\n "
266+ cmd = cmd + " } else {\n "
267+ cmd = cmd + " println \" Not installing '${ filename} ' - this repository will build dependencies for it....\"\n "
268+ cmd = cmd + " }\n "
269+ }
270+ }
271+ writeFile file : ' installAll.groovy' , text : cmd
272+ }
273+
157274@NonCPS // has to be NonCPS or the build breaks on the call to .each
158275def createPackAllFile (list ) {
159276 // creates file because the bat command brakes the loop
@@ -191,11 +308,3 @@ def createRunTestCsProjsFile(list) {
191308 writeFile file : ' runTestCsProjs.groovy' , text : cmd
192309}
193310
194- @NonCPS
195- def upload (item ) {
196- def itemArray = (item =~ / (.*?)(\. [0-9]*\. [0-9]*\. [0-9]*(-SNAPSHOT)?\. nupkg)/ )
197- def dir = itemArray[ 0 ][ 1 ]
198- sh " ./jfrog rt u \" ${ item.path} \" nuget/${ dir} / --flat=false --build-name=" ${env. BRANCH_NAME }" --build-number=${ env.BUILD_NUMBER} "
199- }
200-
201-
0 commit comments