-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjenkinsfile
More file actions
236 lines (218 loc) · 9.91 KB
/
jenkinsfile
File metadata and controls
236 lines (218 loc) · 9.91 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
def R_TOOLS_WINDOWS = "C:\\rtools40\\usr\\bin"
def GAMS_FOR_LINUX = "/opt/gams/gams35.0_linux_x64_64_sfx"
def GAMS_FOR_MACOS = "/Library/Frameworks/GAMS.framework/Versions/35/Resources"
def GAMS_FOR_WINDOWS = "C:\\GAMS\\35"
pipeline {
agent none
options {
parallelsAlwaysFailFast()
disableConcurrentBuilds()
}
stages {
stage('Build') {
parallel {
stage ('linux') {
agent { label 'master' }
environment {
R_LIBS_USER="${env.WORKSPACE}/libpath"
R_GAMS_SYSDIR="${GAMS_FOR_LINUX}"
PATH="${GAMS_FOR_LINUX}:${PATH}"
}
steps {
step([$class: 'WsCleanup'])
checkout scm
sh '''
mkdir libpath
R CMD INSTALL gdxrrw -l "$WORKSPACE/libpath" --build
R CMD build gdxrrw
'''
archiveArtifacts artifacts: '*.tar.gz', fingerprint: true
}
}
stage ('windowsX64') {
agent { label 'windowsX64' }
environment {
R_LIBS_USER="${env.WORKSPACE}/libpath"
R_GAMS_SYSDIR="${GAMS_FOR_WINDOWS}"
PATH="${R_TOOLS_WINDOWS};${GAMS_FOR_WINDOWS};${PATH}"
}
steps {
step([$class: 'WsCleanup'])
checkout scm
bat '''
mkdir libpath
R CMD INSTALL gdxrrw -l "%WORKSPACE%/libpath" --build
'''
archiveArtifacts artifacts: '*.zip', fingerprint: true
}
}
stage ('macos') {
agent { label 'macos' }
environment {
R_LIBS_USER="${env.WORKSPACE}/libpath"
R_GAMS_SYSDIR="${GAMS_FOR_MACOS}"
PATH="${TEX_FOR_MACOS}:${GAMS_FOR_MACOS}:${PATH}"
}
steps {
step([$class: 'WsCleanup'])
checkout scm
sh '''
mkdir libpath
R CMD INSTALL gdxrrw -l "$WORKSPACE/libpath" --build
'''
archiveArtifacts artifacts: '*.tgz', fingerprint: true
}
}
}
}
stage('Test') {
parallel {
stage ('linux') {
agent { label 'master' }
environment {
R_LIBS_USER="${env.WORKSPACE}/libpath"
R_GAMS_SYSDIR="${GAMS_FOR_LINUX}"
PATH="${GAMS_FOR_LINUX}:${PATH}"
}
steps {
sh '''
cd libpath/gdxrrw/tests
Rscript tAll.R
'''
}
}
stage ('windowsX64') {
agent { label 'windowsX64' }
environment {
R_LIBS_USER="${env.WORKSPACE}\\libpath"
R_GAMS_SYSDIR="${GAMS_FOR_WINDOWS}"
PATH="${GAMS_FOR_WINDOWS};${PATH}"
}
steps {
bat '''
cd libpath\\gdxrrw\\tests
rscript tAll.R
'''
}
}
stage ('macos') {
agent { label 'macos' }
environment {
R_LIBS_USER="${env.WORKSPACE}/libpath"
R_GAMS_SYSDIR="${GAMS_FOR_MACOS}"
PATH="${GAMS_FOR_MACOS}:${PATH}"
}
steps {
sh '''
cd libpath/gdxrrw/tests
rscript tAll.R
'''
}
}
}
}
stage('Deploy to GitHub') {
agent { label 'master' }
when {
expression { return currentBuild.currentResult == "SUCCESS" }
tag pattern: "v\\d+\\.\\d+\\.\\d+.*", comparator: "REGEXP"
}
steps {
sh '''
mkdir -p artifacts
'''
copyArtifacts filter: '*.tar.gz, *.tgz, *.zip', fingerprintArtifacts: true, projectName: '${JOB_NAME}', selector: specific('${BUILD_NUMBER}'), target: 'artifacts'
withCredentials([string(credentialsId: '18e8f0e0-f27a-4358-b70f-04acec1e9617', variable: 'GITHUB_TOKEN')]) {
sh '''#!/bin/bash -xe
export GDXRRW_VERSION=$(grep "^Version:" gdxrrw/DESCRIPTION | cut -f2 -d" ")
CHANGELOG=""
foundFirst="false"
while IFS="" read -r line
do
if [[ $line =~ ^Version.* ]] && [[ $foundFirst == "true" ]]; then
break
elif [[ $line =~ ^Version.* ]]; then
CHANGELOG+=$line$'\n'
foundFirst="true"
else
CHANGELOG+=$line$'\n'
fi
done < CHANGELOG
## GitHub parameters
export GITHUB_TOKEN=${GITHUB_TOKEN}
GITHUB_RELEASE_ADDRESS="https://github.com/GAMS-dev/gdxrrw/releases/tag/${TAG_NAME}"
GITHUB_ORGA=GAMS-dev
GITHUB_REPO=gdxrrw
## delete old release if needed
RELEASE_DELETED=0
github-release delete --user $GITHUB_ORGA --repo $GITHUB_REPO --tag ${TAG_NAME} && RELEASE_DELETED=0 || RELEASE_DELETED=1
if [[ $RELEASE_DELETED -eq 0 ]]; then
echo "Release deleted"
else
echo "No release to delete"
fi
## create a GitHub release
if [[ ${TAG_NAME} =~ ^v[0-9]+\\.[0-9]+\\.[0-9]+$ ]]; then
github-release release --user $GITHUB_ORGA --repo $GITHUB_REPO --tag ${TAG_NAME} --description "${CHANGELOG}"
elif [[ ${TAG_NAME} =~ ^v[0-9]+\\.[0-9]+\\.[0-9]+-rc$ ]]; then
github-release release --user $GITHUB_ORGA --repo $GITHUB_REPO --tag ${TAG_NAME} --pre-release --description "${CHANGELOG}"
fi
if [[ ${TAG_NAME} =~ ^v[0-9]+\\.[0-9]+\\.[0-9]+$ ]]; then
## upload artifacts to GitHub
cd artifacts
ls -al
parallel github-release upload -R --user $GITHUB_ORGA --repo $GITHUB_REPO --tag ${TAG_NAME} --name {} --file {} ::: *.*
fi
'''
}
}
}
stage('Mirror Wiki to GitHub') {
agent { label 'master' }
when {
expression { return currentBuild.currentResult == "SUCCESS" }
tag pattern: "v\\d+\\.\\d+\\.\\d+.*", comparator: "REGEXP"
}
steps {
withCredentials([file(credentialsId: '929c2dc4-ebee-43cc-a594-62a8cb9196a3', variable: 'GITLAB_KEY_FILE')]) {
sh '''
ssh-agent bash -c 'ssh-add ${GITLAB_KEY_FILE}; git clone git@git.gams.com:devel/gdxrrw.wiki.git'
'''
}
withCredentials([string(credentialsId: '18e8f0e0-f27a-4358-b70f-04acec1e9617', variable: 'GITHUB_TOKEN')]) {
sh '''
cd gdxrrw.wiki
git push --mirror https://mrmontag:${GITHUB_TOKEN}@github.com/GAMS-dev/gdxrrw.wiki.git
'''
}
}
}
stage('Deploy to CloudFront') {
agent { label 'master' }
when {
expression { return currentBuild.currentResult == "SUCCESS" }
tag pattern: "v\\d+\\.\\d+\\.\\d+.*", comparator: "REGEXP"
}
steps {
withCredentials([string(credentialsId: 'bcd47003-0790-442d-ba1f-5538b4b5482c', variable: 'S3_URL'), string(credentialsId: '3ca54edd-0357-407f-84bf-317fa1b4c20d', variable: 'S3_ACCESS_KEY'), string(credentialsId: 'f4bd9039-889c-401b-b0c6-455b73147c7c', variable: 'S3_SECRET_KEY')]) {
sh '''#!/bin/bash -xe
## change to artifact location
cd artifacts
## folder name which matches the current tag, like v0.10.2 or v0.11.0-rc
FOLDER_NAME="${TAG_NAME}"
## create gdxrrw version directory
mkdir -p $FOLDER_NAME
## move artifacts to correct location
mv *.tgz *.tar.gz *.zip $FOLDER_NAME
## URL to S3 gdxrrw
URL=${S3_URL}/gdxrrw/
## S3 upload to gams.com
s3cmd sync --acl-public ./ $URL --access_key=${S3_ACCESS_KEY} --secret_key=${S3_SECRET_KEY}
## S3 content listing
s3cmd ls -r $URL --access_key=${S3_ACCESS_KEY} --secret_key=${S3_SECRET_KEY}
'''
}
}
}
}
}