File: Jenkinsfile

package info (click to toggle)
node-shiny-server 1.5.20.1002-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,740 kB
  • sloc: javascript: 7,112; sh: 933; cpp: 303; python: 155; makefile: 34
file content (132 lines) | stat: -rw-r--r-- 4,879 bytes parent folder | download | duplicates (2)
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
#!groovy

properties([
    disableConcurrentBuilds(),
    buildDiscarder(logRotator(artifactDaysToKeepStr: '',
                              artifactNumToKeepStr: '',
                              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: 'github-rstudio-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}/"
  }

}

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
                              """
                          }
                          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)
                    }
                }
            }
        }
        parallel parallel_containers

        if (env.BRANCH_NAME == 'master') {
          build job: 'shiny/test-shiny-server-os', wait: false
          sendNotifications slack_channel: SLACK_CHANNEL
        }
    }

} catch(err) {
   sendNotifications slack_channel: SLACK_CHANNEL, result: 'FAILURE'
   error("failed: ${err}")
}