forked from rstudio/rstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
151 lines (137 loc) · 7.22 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
#!groovy
properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '',
numToKeepStr: '100')),
parameters([string(name: 'RSTUDIO_VERSION_MAJOR', defaultValue: '1', description: 'RStudio Major Version'),
string(name: 'RSTUDIO_VERSION_MINOR', defaultValue: '1', description: 'RStudio Minor Version'),
string(name: 'RSTUDIO_VERSION_PATCH', defaultValue: '0', description: 'RStudio Patch Version'),
string(name: 'SLACK_CHANNEL', defaultValue: '#rstudio', description: 'Slack channel to publish build message.'),
string(name: 'OS_FILTER', defaultValue: '', description: 'Pattern to limit builds by matching OS'),
string(name: 'ARCH_FILTER', defaultValue: '', description: 'Pattern to limit builds by matching ARCH'),
string(name: 'FLAVOR_FILTER', defaultValue: '', description: 'Pattern to limit builds by matching FLAVOR')
])
])
def resolve_deps(type, arch, variant) {
def linux_bin = (arch == 'i386') ? 'linux32' : '' // only required in centos-land.
switch ( type ) {
case "DEB":
sh "cd dependencies/linux && ./install-dependencies-debian --exclude-qt-sdk && cd ../.."
break
case "RPM":
if (variant == 'SLES') {
sh "cd dependencies/linux && ${linux_bin} ./install-dependencies-zypper --exclude-qt-sdk && cd ../.."
} else {
sh "cd dependencies/linux && ${linux_bin} ./install-dependencies-yum --exclude-qt-sdk && cd ../.."
}
break
}
}
def compile_package(type, flavor, variant) {
def env = "RSTUDIO_VERSION_MAJOR=${RSTUDIO_VERSION_MAJOR} RSTUDIO_VERSION_MINOR=${RSTUDIO_VERSION_MINOR} RSTUDIO_VERSION_PATCH=${RSTUDIO_VERSION_PATCH}"
sh "cd package/linux && ${env} ./make-${flavor}-package ${type} clean ${variant} && cd ../.."
}
def s3_upload(type, flavor, os, arch) {
sh "aws s3 cp package/linux/build-${flavor.capitalize()}-${type}/rstudio-*.${type.toLowerCase()} s3://rstudio-ide-build/${flavor}/${os}/${arch}/"
}
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 get_type_from_os(os) {
def type
// groovy switch case regex is broken in pipeline
// https://issues.jenkins-ci.org/browse/JENKINS-37214
if (os.contains('centos')) {
type = 'RPM'
} else {
type = 'DEB'
}
return type
}
def limit_builds(containers) {
// '' (empty string) as regex matches all
def limited_containers = []
for (int i = 0; i < containers.size(); i++) {
def it = containers[i]
// negate-fest. String.contains() can't work in the positive with empty strings
if (!(!it.os.contains(OS_FILTER) || !it.arch.contains(ARCH_FILTER) || !it.flavor.contains(FLAVOR_FILTER))) {
limited_containers << it
}
}
return limited_containers ?: containers // if we limit all, limit none
}
def prepareWorkspace(){ // accessory to clean workspace and checkout
step([$class: 'WsCleanup'])
checkout scm
sh 'git reset --hard && git clean -ffdx' // lifted from rstudio/connect
}
def trigger_external_build(build_name, wait = false) {
// triggers downstream job passing along the important params from this build
build job: build_name, wait: wait, parameters: [string(name: 'RSTUDIO_VERSION_MAJOR', value: RSTUDIO_VERSION_MAJOR),
string(name: 'RSTUDIO_VERSION_MINOR', value: RSTUDIO_VERSION_MINOR),
string(name: 'RSTUDIO_VERSION_PATCH', value: RSTUDIO_VERSION_PATCH),
string(name: 'SLACK_CHANNEL', value: SLACK_CHANNEL)]
}
// make a nicer slack message
rstudioVersion = "${RSTUDIO_VERSION_MAJOR}.${RSTUDIO_VERSION_MINOR}.${RSTUDIO_VERSION_PATCH}"
messagePrefix = "Jenkins ${env.JOB_NAME} build: <${env.BUILD_URL}display/redirect|${env.BUILD_DISPLAY_NAME}>, version: ${rstudioVersion}"
try {
timestamps {
def containers = [
[os: 'precise', arch: 'amd64', flavor: 'desktop', variant: 'trusty'],
[os: 'precise', arch: 'i386', flavor: 'desktop', variant: 'trusty'],
[os: 'precise', arch: 'amd64', flavor: 'server', variant: ''],
[os: 'precise', arch: 'i386', flavor: 'server', variant: ''],
[os: 'centos6', arch: 'x86_64', flavor: 'server', variant: ''],
[os: 'centos6', arch: 'i386', flavor: 'server', variant: ''],
[os: 'centos7', arch: 'x86_64', flavor: 'desktop', variant: ''],
[os: 'centos7', arch: 'i386', flavor: 'desktop', variant: ''],
[os: 'opensuse', arch: 'x86_64', flavor: 'server', variant: 'SLES'],
[os: 'xenial', arch: 'amd64', flavor: 'desktop', variant: 'xenial'],
[os: 'xenial', arch: 'i386', flavor: 'desktop', variant: 'xenial']
]
containers = limit_builds(containers)
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]
node('ide') {
stage('prepare ws/container'){
prepareWorkspace()
def image_tag = "${current_container.os}-${current_container.arch}-${RSTUDIO_VERSION_MAJOR}.${RSTUDIO_VERSION_MINOR}"
container = pullBuildPush(image_name: 'jenkins/ide', dockerfile: "docker/jenkins/Dockerfile.${current_container.os}-${current_container.arch}", image_tag: image_tag, build_args: jenkins_user_build_args())
}
container.inside() {
stage('resolve deps'){
resolve_deps(get_type_from_os(current_container.os), current_container.arch, current_container.variant)
}
stage('compile package') {
compile_package(get_type_from_os(current_container.os), current_container.flavor, current_container.variant)
}
}
stage('upload artifacts') {
s3_upload(get_type_from_os(current_container.os), current_container.flavor, current_container.os, current_container.arch)
}
}
}
}
// trigger macos build if we're in open-source repo
if (env.JOB_NAME == 'IDE/open-source') {
trigger_external_build('IDE/macos')
}
parallel parallel_containers
// trigger downstream pro-docs build if we're finished building the pro variants
if (env.JOB_NAME == 'IDE/pro') {
trigger_external_build('IDE/pro-docs')
}
slackSend channel: SLACK_CHANNEL, color: 'good', message: "${messagePrefix} passed"
}
} catch(err) {
slackSend channel: SLACK_CHANNEL, color: 'bad', message: "${messagePrefix} failed: ${err}"
error("failed: ${err}")
}