|
| 1 | +def kubernetes_config = """ |
| 2 | +apiVersion: v1 |
| 3 | +kind: Pod |
| 4 | +spec: |
| 5 | + containers: |
| 6 | + - name: node |
| 7 | + image: eclipseglsp/ci:alpine-v5.0 |
| 8 | + tty: true |
| 9 | + resources: |
| 10 | + limits: |
| 11 | + memory: "2Gi" |
| 12 | + cpu: "1" |
| 13 | + requests: |
| 14 | + memory: "2Gi" |
| 15 | + cpu: "1" |
| 16 | + command: |
| 17 | + - cat |
| 18 | + volumeMounts: |
| 19 | + - mountPath: "/home/jenkins" |
| 20 | + name: "jenkins-home" |
| 21 | + readOnly: false |
| 22 | + - mountPath: "/.yarn" |
| 23 | + name: "yarn-global" |
| 24 | + readOnly: false |
| 25 | + - mountPath: "/.cache" |
| 26 | + name: "playwright-cache" |
| 27 | + readOnly: false |
| 28 | + volumes: |
| 29 | + - name: "jenkins-home" |
| 30 | + emptyDir: {} |
| 31 | + - name: "yarn-global" |
| 32 | + emptyDir: {} |
| 33 | + - name: "playwright-cache" |
| 34 | + emptyDir: {} |
| 35 | +""" |
| 36 | + |
| 37 | +pipeline { |
| 38 | + agent { |
| 39 | + kubernetes { |
| 40 | + label 'glsp-theia-agent-pod' |
| 41 | + yaml kubernetes_config |
| 42 | + } |
| 43 | + } |
| 44 | + options { |
| 45 | + buildDiscarder logRotator(numToKeepStr: '15') |
| 46 | + } |
| 47 | + |
| 48 | + environment { |
| 49 | + YARN_CACHE_FOLDER = "${env.WORKSPACE}/yarn-cache" |
| 50 | + SPAWN_WRAP_SHIM_ROOT = "${env.WORKSPACE}" |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + stages { |
| 55 | + stage('Build') { |
| 56 | + steps { |
| 57 | + timeout(30) { |
| 58 | + container('node') { |
| 59 | + sh "yarn install --unsafe-perm" |
| 60 | + script { |
| 61 | + // Fail the step if there are uncommited changes to the yarn.lock file |
| 62 | + if (sh(returnStatus: true, script: 'git diff --name-only | grep -q "^yarn.lock"') == 0) { |
| 63 | + echo 'The yarn.lock file has uncommited changes!' |
| 64 | + error 'The yarn.lock file has uncommited changes!' |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + stage('Codechecks (ESLint)'){ |
| 73 | + steps { |
| 74 | + container('node') { |
| 75 | + timeout(30){ |
| 76 | + sh "yarn lint:ci" |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + stage('Deploy (main only)') { |
| 83 | + when { |
| 84 | + allOf { |
| 85 | + branch 'main' |
| 86 | + expression { |
| 87 | + /* Only trigger the deployment job if the changeset contains changes in |
| 88 | + the `packages` or `examples/workflow-theia` directory */ |
| 89 | + sh(returnStatus: true, script: 'git diff --name-only HEAD^ | grep -q "^packages\\|examples/workflow-test"') == 0 |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + steps { |
| 94 | + container('node') { |
| 95 | + timeout(30) { |
| 96 | + withCredentials([string(credentialsId: 'npmjs-token', variable: 'NPM_AUTH_TOKEN')]) { |
| 97 | + sh 'printf "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n" >> $WORKSPACE/.npmrc' |
| 98 | + } |
| 99 | + sh 'git config user.email "[email protected]"' |
| 100 | + sh 'git config user.name "eclipse-glsp-bot"' |
| 101 | + sh 'yarn publish:next' |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + post { |
| 109 | + success { |
| 110 | + // Record & publish ESLint issues |
| 111 | + recordIssues enabledForFailure: true, publishAllIssues: true, aggregatingResults: true, |
| 112 | + tools: [esLint(pattern: 'node_modules/**/*/eslint.xml')], |
| 113 | + qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]] |
| 114 | + } |
| 115 | + failure { |
| 116 | + script { |
| 117 | + if (env.BRANCH_NAME == 'main') { |
| 118 | + echo "Build result FAILURE: Send email notification to ${EMAIL_TO}" |
| 119 | + emailext attachLog: true, |
| 120 | + |
| 121 | + body: 'Job: ${JOB_NAME}<br>Build Number: ${BUILD_NUMBER}<br>Build URL: ${BUILD_URL}', |
| 122 | + mimeType: 'text/html', subject: 'Build ${JOB_NAME} (#${BUILD_NUMBER}) FAILURE', to: "${EMAIL_TO}" |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + unstable { |
| 127 | + script { |
| 128 | + if (env.BRANCH_NAME == 'main') { |
| 129 | + echo "Build result UNSTABLE: Send email notification to ${EMAIL_TO}" |
| 130 | + emailext attachLog: true, |
| 131 | + |
| 132 | + body: 'Job: ${JOB_NAME}<br>Build Number: ${BUILD_NUMBER}<br>Build URL: ${BUILD_URL}', |
| 133 | + mimeType: 'text/html', subject: 'Build ${JOB_NAME} (#${BUILD_NUMBER}) UNSTABLE', to: "${EMAIL_TO}" |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + fixed { |
| 138 | + script { |
| 139 | + if (env.BRANCH_NAME == 'main') { |
| 140 | + echo "Build back to normal: Send email notification to ${EMAIL_TO}" |
| 141 | + emailext attachLog: false, |
| 142 | + |
| 143 | + body: 'Job: ${JOB_NAME}<br>Build Number: ${BUILD_NUMBER}<br>Build URL: ${BUILD_URL}', |
| 144 | + mimeType: 'text/html', subject: 'Build ${JOB_NAME} back to normal (#${BUILD_NUMBER})', to: "${EMAIL_TO}" |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | +} |
0 commit comments