Sergey Otpuschennikov | aad1ae0 | 2020-09-11 19:33:51 +0400 | [diff] [blame] | 1 | #!groovy |
| 2 | |
| 3 | def main() { |
| 4 | String gitUrl = "${env.GERRIT_SCHEME}://${env.GERRIT_HOST}:${env.GERRIT_PORT}/${env.GERRIT_PROJECT}" |
| 5 | String gitRef = env.GERRIT_REFSPEC |
| 6 | |
| 7 | stage('SCM checkout') { |
| 8 | checkout \ |
| 9 | $class: 'GitSCM', |
| 10 | branches: [[ |
| 11 | name: 'FETCH_HEAD' |
| 12 | ]], |
| 13 | userRemoteConfigs: [[ |
| 14 | url: gitUrl, |
| 15 | refspec: gitRef, |
| 16 | credentialsId: env.GIT_CREDENTIALS_ID |
| 17 | ]], |
| 18 | extensions: [[ |
| 19 | $class: 'WipeWorkspace' |
| 20 | ]] |
| 21 | } |
| 22 | |
| 23 | stage('Shellcheck') { |
| 24 | sh '''#!/bin/bash -ex |
| 25 | git show --name-only --diff-filter=AM \ |
| 26 | | grep -E '.sh$' \ |
| 27 | | xargs --no-run-if-empty shellcheck -e SC1090,SC2013,SC2154,SC2029 |
| 28 | ''' |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | String podTpl = """ |
| 33 | apiVersion: "v1" |
| 34 | kind: "Pod" |
| 35 | spec: |
| 36 | securityContext: |
| 37 | runAsUser: 1000 |
| 38 | containers: |
| 39 | - name: "main" |
| 40 | image: "${env.DOCKER_IMAGE}" |
| 41 | command: |
| 42 | - "cat" |
| 43 | securityContext: |
| 44 | privileged: false |
| 45 | tty: true |
| 46 | """ |
| 47 | if (env.K8S_CLUSTER == 'unset') { |
| 48 | node(env.NODE_LABEL) { |
| 49 | docker.image(env.DOCKER_IMAGE).inside('--entrypoint=""') { |
| 50 | main() |
| 51 | } |
| 52 | } |
| 53 | } else { |
| 54 | podTemplate( |
| 55 | cloud: env.K8S_CLUSTER, |
| 56 | yaml: podTpl, |
| 57 | showRawYaml: false |
| 58 | ) { |
| 59 | node(POD_LABEL) { |
| 60 | container('main') { |
| 61 | main() |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |