-
Notifications
You must be signed in to change notification settings - Fork 290
/
Jenkinsfile.internal
174 lines (152 loc) · 6.42 KB
/
Jenkinsfile.internal
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
#!groovy
properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(artifactDaysToKeepStr: '',
artifactNumToKeepStr: '100',
daysToKeepStr: '',
numToKeepStr: '100')),
parameters([string(name: 'SLACK_CHANNEL', defaultValue: '#shiny-server', description: 'Slack channel to publish build message.')])
])
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 getBucketFromJobName(job) {
def bucket = 'rstudio-shiny-server-os-build'
if (job.contains('shiny-server-pro')) {
bucket = 'rstudio-shiny-server-pro-build'
}
return bucket
}
def getPathFromBranch(branch_name) {
def path = ''
if (branch_name != 'master') {
path = "branches/${branch_name.replaceAll('/','-')}"
}
return path
}
def getPackageTypeFromOs(os) {
def type = ''
if (os.contains('ubuntu')) {
type = 'deb'
} else {
type = 'rpm'
}
return type
}
def s3_upload(os, arch) {
// Derive path components from job name and OS
def bucket = getBucketFromJobName(env.JOB_NAME)
def path = getPathFromBranch(env.BRANCH_NAME)
def type = getPackageTypeFromOs(os)
// Determine the name of the file we just built
def file = sh(
script: "basename \$(ls packaging/build/*.${type})",
returnStdout: true
).trim()
if (path.empty) {
// If the path is empty, we're on master and don't want 'master' to appear
// in the object paths.
sh "aws s3 cp packaging/build/${file} s3://${bucket}/${os}/${arch}/"
sh "aws s3 cp packaging/build/VERSION s3://${bucket}/${os}/${arch}/"
// Publish the uploaded build to the dailies page (only for builds from
// master)
withCredentials([usernamePassword(credentialsId: 'posit-jenkins', usernameVariable: 'GITHUB_USERNAME', passwordVariable: 'GITHUB_PAT')]) {
sh "docker/jenkins/publish-build.sh --platform ${os} --url https://s3.amazonaws.com/${bucket}/${os}/${arch}/${file} --pat ${GITHUB_PAT} --file packaging/build/${file}"
}
} else {
// If the path is non-empty, we're on a branch other than master, and its
// name should be included in the object paths.
sh "aws s3 cp packaging/build/${file} s3://${bucket}/${path}/${os}/${arch}/"
sh "aws s3 cp packaging/build/VERSION s3://${bucket}/${path}/${os}/${arch}/"
}
}
def cloudsmith_upload(os) {
// Derive path components from job name and OS
def type = getPackageTypeFromOs(os)
// Determine the name of the file we just built
def file = sh(
script: "basename \$(ls packaging/build/*.${type})",
returnStdout: true
).trim()
if (env.BRANCH_NAME == 'master') {
if (type == 'rpm') {
sh "cloudsmith push ${type} --verbose rstudio/internal/el/7 packaging/build/${file}"
sh "cloudsmith push ${type} --verbose rstudio/internal/el/8 packaging/build/${file}"
} else if (type == 'deb') {
sh "cloudsmith push ${type} --verbose rstudio/internal/ubuntu/bionic packaging/build/${file}"
sh "cloudsmith push ${type} --verbose rstudio/internal/ubuntu/focal packaging/build/${file}"
sh "cloudsmith push ${type} --verbose rstudio/internal/ubuntu/jammy packaging/build/${file}"
} else {
sh "echo Unsupported file type: ${type}"
}
} else {
sh "echo Skip pushing non-master branch to cloudsmith"
}
}
try {
timestamps {
def containers = [
[os: 'ubuntu-18.04', arch: 'x86_64'],
[os: 'centos7', arch: 'x86_64']
]
def parallel_containers = [:]
for (int i = 0; i < containers.size(); i++) {
def index = i
parallel_containers["${containers[i].os}-${containers[i].arch}"] = {
def current_container = containers[index]
node('docker') {
stage('prepare ws/container'){
prepareWorkspace()
def image_tag = "${current_container.os}-${current_container.arch}"
container = pullBuildPush(image_name: 'jenkins/shiny-server', dockerfile: "docker/jenkins/Dockerfile.${current_container.os}", image_tag: image_tag, build_arg_jenkins_uid: 'JENKINS_UID', build_arg_jenkins_gid: 'JENKINS_GID')
}
container.inside() {
withEnv(["OS=${current_container.os}", "ARCH=${current_container.arch}"]) {
stage('make package'){
sh """
if [ -f ./packaging/make-package-jenkins.sh ]; then
./packaging/make-package-jenkins.sh
else
./packaging/make-package.sh
fi
"""
archiveArtifacts artifacts: "packaging/build/*.rpm,packaging/build/*.deb"
}
stage('run tests') {
// Need npm install so npm modules required for testing are available
sh './bin/node ./node_modules/mocha/bin/mocha test'
}
}
}
stage('check licenses') {
sh 'tools/preflight.sh'
}
/*
stage('s3 upload') {
s3_upload(current_container.os, current_container.arch)
}
*/
stage('cloudsmith upload') {
docker.image('python:3.9-slim-buster').inside("-u root --privileged") {
withCredentials(bindings: [
string(credentialsId: 'cloudsmith_api_key', variable: 'CLOUDSMITH_API_KEY')
]) {
sh "pip install --upgrade cloudsmith-cli"
cloudsmith_upload(current_container.os)
}
} // docker image inside
} // stage cloudsmith upload
}
}
}
parallel parallel_containers
if (env.BRANCH_NAME == 'master') {
sendNotifications slack_channel: SLACK_CHANNEL
}
}
} catch(err) {
sendNotifications slack_channel: SLACK_CHANNEL, result: 'FAILURE'
error("failed: ${err}")
}