-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
217 lines (190 loc) · 8.46 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
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
#!dgroovy
//
// JenkinsFile
//
// Copyright (C) 2019-20 by RStudio, PBC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
properties([
disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '',
numToKeepStr: '100')),
parameters([string(name: 'RLP_SDK_VERSION_MAJOR', defaultValue: '1', description: 'RStudio Launcher Plugin SDK Major Version'),
string(name: 'RLP_SDK_VERSION_MINOR', defaultValue: '0', description: 'RStudio Launcher Plugin SDK Minor Version'),
string(name: 'SLACK_CHANNEL', defaultValue: '#ide-builds', description: 'Slack channel to publish build message.'),
booleanParam(name: 'UPLOAD_PACKAGE', description: 'When checked, pushes the generated package to AWS S3.')
])
])
def create_package() {
// start with major, minor, and patch versions
def env = "RLP_SDK_VERSION_MAJOR=${rlpSdkVersionMajor} RLP_SDK_VERSION_MINOR=${rlpSdkVersionMinor} RLP_SDK_VERSION_PATCH=${rlpSdkVersionPatch}"
// build the package
sh "${env} docker/package/make-package.sh"
}
def generate_documentation() {
sh "tools/generate-documentation.sh '${rlpSdkVersionMajor}.${rlpSdkVersionMinor}.${rlpSdkVersionPatch}'"
}
def build_source(type) {
// start with major, minor, and patch versions
def env = "RLP_SDK_VERSION_MAJOR=${rlpSdkVersionMajor} RLP_SDK_VERSION_MINOR=${rlpSdkVersionMinor} RLP_SDK_VERSION_PATCH=${rlpSdkVersionPatch}"
// currently our nodes have access to 4 cores, so spread out the compile job
// a little (currently using up all 4 cores causes problems)
env = "${env} MAKEFLAGS=-j3 CMAKE_BUILD_TYPE=${type}"
sh "${env} docker/jenkins/compile.sh"
}
def run_tests(type) {
// attempt to run tests
sh "cd .."
sh "tools/run-all-tests.sh cmake-build-${type}"
}
def s3_upload() {
def version = "${rlpSdkVersionMajor}.${rlpSdkVersionMinor}.${rlpSdkVersionPatch}"
def buildFolder = "docker/package"
def packageFile = sh (
script: "basename `ls ${buildFolder}/*-${version}.tar.gz`",
returnStdout: true
).trim()
// copy installer to s3
sh "aws s3 cp ${buildFolder}/${packageFile} s3://rstudio-launcher-plugin-sdk/"
// copy documentation to s3
sh "aws s3 sync docs/ApiRefHtml s3://docs.rstudio.com/rlps/apiref/${version}/"
sh "aws s3 sync docs/ApiRefHtml s3://docs.rstudio.com/rlps/apiref/latest/"
sh "aws s3 sync docs/QuickStartHtml s3://docs.rstudio.com/rlps/quickstart/${version}/"
sh "aws s3 sync docs/QuickStartHtml s3://docs.rstudio.com/rlps/quickstart/latest/"
sh "aws s3 sync docs/DevGuideHtml s3://docs.rstudio.com/rlps/devguide/${version}/"
sh "aws s3 sync docs/DevGuideHtml s3://docs.rstudio.com/rlps/devguide/latest/"
}
def jenkins_user_build_args() {
def jenkins_uid = sh (script: 'id -u jenkins', returnStdout: true).trim()
def jenkins_gid = sh (script: 'id -g jenkins', returnStdout: true).trim()
return " --build-arg JENKINS_UID=${jenkins_uid} --build-arg JENKINS_GID=${jenkins_gid}"
}
def prepareWorkspace() { // accessory to clean workspace and checkout
step([$class: 'WsCleanup'])
checkout scm
sh 'git reset --hard && git clean -ffdx' // lifted from rstudio/connect
}
// forward declare version vars
rlpSdkVersionMajor = 0
rlpSdkVersionMinor = 0
rlpSdkVersionPatch = 0
// make a nicer slack message
messagePrefix = "Jenkins ${env.JOB_NAME} build: <${env.BUILD_URL}display/redirect|${env.BUILD_DISPLAY_NAME}>"
try {
timestamps {
def containers = [
[os: 'focal', arch: 'amd64', flavor: 'Release'],
[os: 'focal', arch: 'amd64', flavor: 'Debug'],
[os: 'centos8', arch: 'x86_64', flavor: 'Release']
]
// create the version we're about to build
node('docker') {
stage('Prepare Versioning Container') {
prepareWorkspace()
retry(1) {
container = pullBuildPush(image_name: 'jenkins/rlp-sdk', dockerfile: "docker/jenkins/Dockerfile.versioning", image_tag: "rlp-sdk-versioning", build_args: jenkins_user_build_args())
}
container.inside() {
stage('Bump Version') {
def rlpSdkVersion = sh (
script: "docker/jenkins/rlps-version.sh bump ${params.RLP_SDK_VERSION_MAJOR}.${params.RLP_SDK_VERSION_MINOR}",
returnStdout: true
).trim()
echo "RStudio Launcher Plugin SDK build version: ${rlpSdkVersion}"
def components = rlpSdkVersion.split('\\.')
// extract version
rlpSdkVersionMajor = components[0]
rlpSdkVersionMinor = components[1]
rlpSdkVersionPatch = components[2]
// update slack message to include build version
messagePrefix = "Jenkins ${env.JOB_NAME} build: <${env.BUILD_URL}display/redirect|${env.BUILD_DISPLAY_NAME}>, version: ${rlpSdkVersion}"
}
}
}
}
// build each variant in parallel
def parallel_containers = [:]
for (int i = 0; i < containers.size(); i++) {
def index = i
parallel_containers["${containers[i].os}-${containers[i].arch}-${containers[i].flavor}"] = {
def current_container = containers[index]
def container
node('docker') {
stage('Prepare B&T Container') {
prepareWorkspace()
def image_tag = "${current_container.os}-${current_container.arch}-${params.RLP_SDK_VERSION_MAJOR}.${params.RLP_SDK_VERSION_MINOR}"
retry(1) {
withCredentials([usernameColonPassword(credentialsId: 'posit-jenkins', variable: "github_login")]) {
def github_args = '--build-arg GITHUB_LOGIN=${github_login}'
container = pullBuildPush(image_name: 'jenkins/rlp-sdk', dockerfile: "docker/jenkins/Dockerfile.${current_container.os}-${current_container.arch}", image_tag: image_tag, build_args: github_args + " " + jenkins_user_build_args())
}
}
}
stage('Build and Test') {
container.inside("--privileged") {
stage('Compile Source') {
retry(1) {
build_source("${current_container.flavor}")
}
}
stage('Run Tests') {
run_tests("${current_container.flavor}")
}
}
}
}
}
}
parallel parallel_containers
stage ('Package and Upload SDK') {
node ('docker') {
stage('Prepare Packaging Container') {
prepareWorkspace()
retry(1) {
container = pullBuildPush(image_name: 'jenkins/rlp-sdk', dockerfile: "docker/jenkins/Dockerfile.packaging", image_tag: "rlp-sdk-packaging", build_args: jenkins_user_build_args())
}
container.inside() {
stage('Generate Documentation') {
retry(1) {
generate_documentation()
}
}
stage('Create Package') {
retry(1) {
create_package()
}
}
}
if (params.get('UPLOAD_PACKAGE') == true) {
stage('Upload Package') {
s3_upload()
}
}
}
}
}
slackSend channel: params.get('SLACK_CHANNEL', '#ide-builds'), color: 'good', message: "${messagePrefix} passed"
}
} catch(err) {
slackSend channel: params.get('SLACK_CHANNEL', '#ide-builds'), color: 'bad', message: "${messagePrefix} failed: ${err}"
error("failed: ${err}")
}