forked from itext/itext-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
182 lines (168 loc) · 6.44 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env groovy
@Library('pipeline-library')_
def schedule = env.BRANCH_NAME.contains('master') ? '@monthly' : env.BRANCH_NAME == 'develop' ? '@midnight' : ''
pipeline {
agent { label 'windows' }
options {
ansiColor('xterm')
buildDiscarder(logRotator(artifactNumToKeepStr: '1'))
parallelsAlwaysFailFast()
retry(1)
skipStagesAfterUnstable()
timeout(time: 60, unit: 'MINUTES')
timestamps()
}
triggers {
cron(schedule)
}
stages {
stage('Clean workspace') {
options {
timeout(time: 5, unit: 'MINUTES')
}
steps {
cleanWs deleteDirs: true, patterns: [
[pattern: 'packages', type: 'INCLUDE'],
[pattern: 'global-packages', type: 'INCLUDE'],
[pattern: 'tmp/NuGetScratch', type: 'INCLUDE'],
[pattern: 'http-cache', type: 'INCLUDE'],
[pattern: 'plugins-cache', type: 'INCLUDE'],
[pattern: '**/obj', type: 'INCLUDE'],
[pattern: '**/bin', type: 'INCLUDE']
]
}
}
stage('Compile') {
options {
timeout(time: 20, unit: 'MINUTES')
}
steps {
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}"]) {
bat "\"${env.NuGet}\" restore iTextCore.netstandard.sln"
bat "dotnet restore iTextCore.netstandard.sln"
bat "dotnet build iTextCore.netstandard.sln --configuration Release --source ${env.WORKSPACE}/packages"
script {
createPackAllFile(findFiles(glob: '**/*.nuspec'))
load 'packAll.groovy'
}
}
}
}
stage('Run Tests') {
options {
timeout(time: 60, unit: 'MINUTES')
}
steps {
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}"]) {
script {
createRunTestDllsFile(findFiles(glob: '**/itext.*.tests.dll'))
load 'runTestDlls.groovy'
createRunTestCsProjsFile(findFiles(glob: '**/itext.*.tests.netstandard.csproj'))
load 'runTestCsProjs.groovy'
}
}
}
}
stage('Artifactory Deploy') {
options {
timeout(time: 5, unit: 'MINUTES')
}
when {
anyOf {
branch "master"
branch "develop"
branch "7.0"
branch "7.0-master"
}
}
steps {
script {
getAndConfigureJFrogCLI()
findFiles(glob: '*.nupkg').each { item ->
upload(item)
}
}
}
}
stage('Archive Artifacts') {
options {
timeout(time: 5, unit: 'MINUTES')
}
steps {
archiveArtifacts allowEmptyArchive: true, artifacts: '*.nupkg'
}
}
}
post {
always {
echo 'One way or another, I have finished \uD83E\uDD16'
}
success {
echo 'I succeeeded! \u263A'
cleanWs deleteDirs: true
}
unstable {
echo 'I am unstable \uD83D\uDE2E'
}
failure {
echo 'I failed \uD83D\uDCA9'
}
changed {
echo 'Things were different before... \uD83E\uDD14'
}
fixed {
script {
if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == 'develop')) {
slackNotifier("#ci", currentBuild.currentResult, "${env.BRANCH_NAME} - Back to normal")
}
}
}
regression {
script {
if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == 'develop')) {
slackNotifier("#ci", currentBuild.currentResult, "${env.BRANCH_NAME} - First failure")
}
}
}
}
}
@NonCPS // has to be NonCPS or the build breaks on the call to .each
def createPackAllFile(list) {
// creates file because the bat command brakes the loop
def cmd = ''
list.each { item ->
if (!item.path.contains("packages")) {
cmd = cmd + "bat '\"${env.NuGet.replace('\\','\\\\')}\" pack \"${item.path.replace('\\','\\\\')}\"'\n"
}
}
writeFile file: 'packAll.groovy', text: cmd
}
@NonCPS // has to be NonCPS or the build breaks on the call to .each
def createRunTestDllsFile(list) {
// creates file because the bat command brakes the loop
def ws = "${env.WORKSPACE.replace('\\','\\\\')}"
def nunit = "${env.'Nunit3-console'.replace('\\','\\\\')}"
def cmd = ''
list.each { item ->
if (!item.path.contains("netcoreapp1.0") && !item.path.contains("obj")) {
cmd = cmd + "bat '\"${nunit}\" \"${ws}\\\\${item.path.replace('\\','\\\\')}\" --result=${item.name}-TestResult.xml'\n"
}
}
writeFile file: 'runTestDlls.groovy', text: cmd
}
@NonCPS // has to be NonCPS or the build breaks on the call to .each
def createRunTestCsProjsFile(list) {
// creates file because the bat command brakes the loop
def ws = "${env.WORKSPACE.replace('\\','\\\\')}"
def cmd = ''
list.each { item ->
cmd = cmd + "bat 'dotnet test ${ws}\\\\${item.path.replace('\\','\\\\')} --framework netcoreapp1.0 --configuration Release --no-build --logger \"trx;LogFileName=results.trx\"'\n"
}
writeFile file: 'runTestCsProjs.groovy', text: cmd
}
@NonCPS
def upload(item) {
def itemArray = (item =~ /(.*?)(\.[0-9]*\.[0-9]*\.[0-9]*(-SNAPSHOT)?\.nupkg)/)
def dir = itemArray[ 0 ][ 1 ]
sh "./jfrog rt u \"${item.path}\" nuget/${dir}/ --flat=false --build-name="${env.BRANCH_NAME}" --build-number=${env.BUILD_NUMBER}"
}