|
| 1 | +#!/usr/bin/env groovy |
| 2 | +@Library('pipeline-library')_ |
| 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 | + retry(1) |
| 15 | + skipStagesAfterUnstable() |
| 16 | + timeout(time: 60, unit: 'MINUTES') |
| 17 | + timestamps() |
| 18 | + } |
| 19 | + |
| 20 | + triggers { |
| 21 | + cron(schedule) |
| 22 | + } |
| 23 | + |
| 24 | + stages { |
| 25 | + stage('Clean workspace') { |
| 26 | + options { |
| 27 | + timeout(time: 5, unit: 'MINUTES') |
| 28 | + } |
| 29 | + 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') { |
| 42 | + options { |
| 43 | + timeout(time: 20, unit: 'MINUTES') |
| 44 | + } |
| 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 iTextCore.netstandard.sln" |
| 48 | + bat "dotnet restore iTextCore.netstandard.sln" |
| 49 | + bat "dotnet build iTextCore.netstandard.sln --configuration Release --source ${env.WORKSPACE}/packages" |
| 50 | + script { |
| 51 | + createPackAllFile(findFiles(glob: '**/*.nuspec')) |
| 52 | + load 'packAll.groovy' |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + stage('Run Tests') { |
| 58 | + options { |
| 59 | + timeout(time: 60, unit: 'MINUTES') |
| 60 | + } |
| 61 | + steps { |
| 62 | + 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}"]) { |
| 63 | + script { |
| 64 | + createRunTestDllsFile(findFiles(glob: '**/itext.*.tests.dll')) |
| 65 | + load 'runTestDlls.groovy' |
| 66 | + createRunTestCsProjsFile(findFiles(glob: '**/itext.*.tests.netstandard.csproj')) |
| 67 | + load 'runTestCsProjs.groovy' |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + stage('Artifactory Deploy') { |
| 73 | + options { |
| 74 | + timeout(time: 5, unit: 'MINUTES') |
| 75 | + } |
| 76 | + when { |
| 77 | + anyOf { |
| 78 | + branch "master" |
| 79 | + branch "develop" |
| 80 | + branch "7.0" |
| 81 | + branch "7.0-master" |
| 82 | + } |
| 83 | + } |
| 84 | + steps { |
| 85 | + script { |
| 86 | + getAndConfigureJFrogCLI() |
| 87 | + findFiles(glob: '*.nupkg').each { item -> |
| 88 | + upload(item) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + stage('Archive Artifacts') { |
| 94 | + options { |
| 95 | + timeout(time: 5, unit: 'MINUTES') |
| 96 | + } |
| 97 | + steps { |
| 98 | + archiveArtifacts allowEmptyArchive: true, artifacts: '*.nupkg' |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + post { |
| 104 | + always { |
| 105 | + echo 'One way or another, I have finished \uD83E\uDD16' |
| 106 | + } |
| 107 | + success { |
| 108 | + echo 'I succeeeded! \u263A' |
| 109 | + cleanWs deleteDirs: true |
| 110 | + } |
| 111 | + unstable { |
| 112 | + echo 'I am unstable \uD83D\uDE2E' |
| 113 | + } |
| 114 | + failure { |
| 115 | + echo 'I failed \uD83D\uDCA9' |
| 116 | + } |
| 117 | + changed { |
| 118 | + echo 'Things were different before... \uD83E\uDD14' |
| 119 | + } |
| 120 | + fixed { |
| 121 | + script { |
| 122 | + if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == 'develop')) { |
| 123 | + slackNotifier("#ci", currentBuild.currentResult, "${env.BRANCH_NAME} - Back to normal") |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | + regression { |
| 128 | + script { |
| 129 | + if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == 'develop')) { |
| 130 | + slackNotifier("#ci", currentBuild.currentResult, "${env.BRANCH_NAME} - First failure") |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | +} |
| 137 | + |
| 138 | +@NonCPS // has to be NonCPS or the build breaks on the call to .each |
| 139 | +def createPackAllFile(list) { |
| 140 | + // creates file because the bat command brakes the loop |
| 141 | + def cmd = '' |
| 142 | + list.each { item -> |
| 143 | + if (!item.path.contains("packages")) { |
| 144 | + cmd = cmd + "bat '\"${env.NuGet.replace('\\','\\\\')}\" pack \"${item.path.replace('\\','\\\\')}\"'\n" |
| 145 | + } |
| 146 | + } |
| 147 | + writeFile file: 'packAll.groovy', text: cmd |
| 148 | +} |
| 149 | + |
| 150 | +@NonCPS // has to be NonCPS or the build breaks on the call to .each |
| 151 | +def createRunTestDllsFile(list) { |
| 152 | + // creates file because the bat command brakes the loop |
| 153 | + def ws = "${env.WORKSPACE.replace('\\','\\\\')}" |
| 154 | + def nunit = "${env.'Nunit3-console'.replace('\\','\\\\')}" |
| 155 | + def cmd = '' |
| 156 | + list.each { item -> |
| 157 | + if (!item.path.contains("netcoreapp1.0") && !item.path.contains("obj")) { |
| 158 | + cmd = cmd + "bat '\"${nunit}\" \"${ws}\\\\${item.path.replace('\\','\\\\')}\" --result=${item.name}-TestResult.xml'\n" |
| 159 | + } |
| 160 | + } |
| 161 | + writeFile file: 'runTestDlls.groovy', text: cmd |
| 162 | +} |
| 163 | + |
| 164 | +@NonCPS // has to be NonCPS or the build breaks on the call to .each |
| 165 | +def createRunTestCsProjsFile(list) { |
| 166 | + // creates file because the bat command brakes the loop |
| 167 | + def ws = "${env.WORKSPACE.replace('\\','\\\\')}" |
| 168 | + def cmd = '' |
| 169 | + list.each { item -> |
| 170 | + cmd = cmd + "bat 'dotnet test ${ws}\\\\${item.path.replace('\\','\\\\')} --framework netcoreapp1.0 --configuration Release --no-build --logger \"trx;LogFileName=results.trx\"'\n" |
| 171 | + } |
| 172 | + writeFile file: 'runTestCsProjs.groovy', text: cmd |
| 173 | +} |
| 174 | + |
| 175 | +@NonCPS |
| 176 | +def upload(item) { |
| 177 | + def itemArray = (item =~ /(.*?)(\.[0-9]*\.[0-9]*\.[0-9]*(-SNAPSHOT)?\.nupkg)/) |
| 178 | + def dir = itemArray[ 0 ][ 1 ] |
| 179 | + sh "./jfrog rt u \"${item.path}\" nuget/${dir}/ --flat=false --build-name="${env.BRANCH_NAME}" --build-number=${env.BUILD_NUMBER}" |
| 180 | +} |
| 181 | + |
| 182 | + |
0 commit comments