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 | echo "Checking out git repository from ${gitUrl} @ ${gitRef}" |
| 9 | |
| 10 | checkout \ |
| 11 | $class: 'GitSCM', |
| 12 | branches: [[ |
| 13 | name: 'FETCH_HEAD' |
| 14 | ]], |
| 15 | userRemoteConfigs: [[ |
| 16 | url: gitUrl, |
| 17 | refspec: gitRef, |
| 18 | credentialsId: env.GIT_CREDENTIALS_ID |
| 19 | ]], |
| 20 | extensions: [[ |
| 21 | $class: 'WipeWorkspace' |
| 22 | ]] |
| 23 | } |
| 24 | |
| 25 | stage('tox') { |
| 26 | sh '''#!/bin/bash -ex |
| 27 | tox -v |
| 28 | ''' |
| 29 | |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | String podTpl = """ |
| 34 | apiVersion: "v1" |
| 35 | kind: "Pod" |
| 36 | spec: |
| 37 | securityContext: |
| 38 | runAsUser: 1000 |
| 39 | containers: |
| 40 | - name: "main" |
| 41 | image: "${env.DOCKER_IMAGE}" |
| 42 | command: |
| 43 | - "cat" |
| 44 | securityContext: |
| 45 | privileged: false |
| 46 | tty: true |
| 47 | """ |
| 48 | |
| 49 | if (env.K8S_CLUSTER == 'unset') { |
| 50 | node(env.NODE_LABEL) { |
| 51 | docker.image(env.DOCKER_IMAGE).inside('--entrypoint=""') { |
| 52 | main() |
| 53 | } |
| 54 | } |
| 55 | } else { |
| 56 | podTemplate( |
| 57 | cloud: env.K8S_CLUSTER, |
| 58 | yaml: podTpl, |
| 59 | showRawYaml: false |
| 60 | ) { |
| 61 | node(POD_LABEL) { |
| 62 | container('main') { |
| 63 | main() |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |