aboutsummaryrefslogtreecommitdiff
path: root/Jenkinsfile
blob: 1bbb84da8b320253591623aadf2245edad4c38a2 (plain)
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
pipeline {
    agent any

    triggers {
      pollSCM('H/1 * * * *')
    }

    environment {
        BUILD_DIR = "dist"
        JS_FILENAME = "grl-panel"
    }

    options {
        skipDefaultCheckout()
    }

    stages {

        stage('setup'){
            steps {
                cleanWs()
                dir("panel-ui") {
                    checkout scmGit(
                        branches: [[name: env.BRANCH_NAME]],
                        extensions: [ cloneOption(shallow: true) ],
                        userRemoteConfigs: [
                            [credentialsId:  'abdeb570-b708-44f3-b857-8a6b06ed9822',
                             url: 'ssh://code.g-r-l.com:6611/panel-ui']
                        ],

                    )
                }
            }
        }

        stage('npm.install') {
            steps {
                dir("panel-ui") {
                    sh "/usr/local/bin/npm install"
                }
            }
        }

        stage('npm.test') {
            steps {
                dir("panel-ui") {
                    sh "/usr/local/bin/npm run test"
                }
            }
        }

        stage('npm.build') {
            when {
                /*  Only build the widget if we're on master or if it's a tag.. otherwise, we don't
                    currently have a reason to build dev branch for testing purposes
                */
                expression {
                    return env.BRANCH_NAME == 'master' || env.TAG_NAME?.trim()
                }
            }

            steps {
                dir("panel-ui") {
                    sh "/usr/local/bin/npm run build"
                    script {
                        def filePath = "dist/grl-panel.js"
                        def minSize = 500 * 1024
                        def size = sh(script: "stat -c%s ${filePath}", returnStdout: true).trim().toInteger()

                        if (size < minSize) {
                            error "Build ${filePath} is too small: ${size} bytes"
                        } else {
                            echo "Build size is acceptable: ${size} bytes"
                        }
                    }
                }
            }
        }

        stage('cdn.deploy.master') {
            when {
                expression { env.BRANCH_NAME == 'master' }
            }
            steps {
                dir("panel-ui") {
                    sh "/usr/bin/rsync -v ${env.BUILD_DIR}/${env.JS_FILENAME}.js grl-cdn:/root/gr-cdn/"
                }
            }
        }

        stage('cdn.deploy.non-master') {
            when {
                expression { env.BRANCH_NAME != 'master' }
            }
            steps {
                dir("panel-ui") {
                    script {
                        def branch = env.BRANCH_NAME
                        echo "Detected branch: ${branch}"
                        def versioned = "${env.BUILD_DIR}/${env.JS_FILENAME}-${branch}.js"
                        sh "cp ${env.BUILD_DIR}/${env.JS_FILENAME}.js ${versioned}"
                    }

                    sh "/usr/bin/rsync -v ${env.BUILD_DIR}/${versioned}.js grl-cdn:/root/gr-cdn/"
                }
            }
        }

        stage('cdn.deploy.tag') {
            when {
                expression {
                    return env.TAG_NAME?.trim()
                }
            }

            steps {
                dir("panel-ui") {
                    script {
                        def tag = env.TAG_NAME
                        echo "Detected tag: ${tag}"
                        def versioned = "${env.BUILD_DIR}/${env.JS_FILENAME}-${tag}.js"
                        sh "cp ${env.BUILD_DIR}/${env.JS_FILENAME}.js ${versioned}"
                    }

                    sh "/usr/bin/rsync -v ${env.BUILD_DIR}/${versioned} grl-cdn:/root/gr-cdn/"

                }
            }
        }

    }

}