Advertisement
--0

bob.groovy

--0
Mar 4th, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 5.58 KB | None | 0 0
  1.  
  2. /**
  3.  *  defaultParametersForGerritEvent Map     default parameters for the Build in case if build is triggered by Gerrit event.
  4.  *                                          This will override parameters existing in params.XXX
  5.  */
  6. Map defaultParametersForGerritEvent = [
  7.     SKIP_BUILD: true,
  8.     SKIP_UNIT_TESTS: false,
  9.     SKIP_INTEGRATION_TESTS: false,
  10.     SKIP_UI_TESTS: true,
  11.     SKIP_RATING: true
  12. ]
  13.  
  14. boolean skipBuild, skipUnitTests, skipIntegrationTests, skipUiTests, skipRating
  15.  
  16.  
  17.  
  18. pipeline {
  19.  
  20.     agent { label 'vm8-linux' }
  21.  
  22.     parameters {
  23.         choice(name: 'INVOKE_PARAMETERS', choices: "Yes\nNo")
  24.         booleanParam(name: 'SKIP_BUILD', defaultValue: false)
  25.         booleanParam(name: 'SKIP_UPLOAD', defaultValue: true)
  26.         booleanParam(name: 'SKIP_UNIT_TESTS', defaultValue: false)
  27.         booleanParam(name: 'SKIP_INTEGRATION_TESTS', defaultValue: false)
  28.         booleanParam(name: 'SKIP_UI_TESTS', defaultValue: true)
  29.         booleanParam(name: 'SKIP_RATING', defaultValue: true)
  30.     }
  31.  
  32.     stages {
  33.  
  34.         stage('Initialization') {
  35.             steps {
  36.                 script {
  37.                     switch (env.GERRIT_EVENT_TYPE) {
  38.                         case [null, '']:
  39.                             echo 'Job has been triggered via Web'
  40.                             break
  41.  
  42.                         case 'patchset_created':
  43.                             echo "Job has been triggered by the new patchset in Gerrit. Url is ${env.GERRIT_PATCHSET_URL}"
  44.                             break
  45.  
  46.                         case 'comment added':
  47.                             echo "Job has been triggered by comment ${env.GERRIT_COMMENT} in Gerrit. Url is ${env.GERRIT_PATCHSET_URL}"
  48.                             break
  49.  
  50.                         default:
  51.                             echo 'Job has been triggered by unknown reason'
  52.                             break
  53.                     }
  54.  
  55.                     sh '''
  56.                        echo "Hostname: $(hostname)"
  57.                        echo "Environment variables"
  58.                        printenv | sort
  59.                        echo "Working directory: $(pwd)"
  60.                        tree -d
  61.                    '''
  62.  
  63.                     if (params.INVOKE_PARAMETERS == 'Yes' && !env.GERRIT_EVENT_TYPE) {
  64.                         currentBuild.result = 'FAILED'
  65.                         error 'Parameters have been invoked! Aborted.'
  66.                     }
  67.  
  68.                     skipBuild =             env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_BUILD : params.SKIP_BUILD
  69.                     skipUnitTests =         env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_UNIT_TESTS : params.SKIP_UNIT_TESTS
  70.                     skipIntegrationTests =  env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_INTEGRATION_TESTS : params.SKIP_INTEGRATION_TESTS
  71.                     skipUiTests =           env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_UI_TESTS : params.SKIP_UI_TESTS
  72.                     skipRating =            env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_RATING : params.SKIP_RATING
  73.                 }
  74.             }
  75.         }
  76.  
  77.         stage('Fetch carbon-ui') {
  78.             steps {
  79.                 sh """#!/usr/bin/env bash
  80.  
  81.                    if [[ "$(git -C ./carbon-ui rev-parse --is-inside-work-tree 2> /dev/null)" == "true" ]]
  82.                    then
  83.                        git -C ./carbon-ui clean --force -d -x
  84.                        git -C ./carbon-ui reset --hard --recurse-submodules
  85.                        git -C ./carbon-ui checkout --recurse-submodules develop
  86.                        git -C ./carbon-ui pull --recurse-submodules
  87.                    else
  88.                        git clone --recurse-submodules ssh://gerritSunnyvale/carbon-ui
  89.                    fi
  90.                """
  91.             }
  92.         }
  93.  
  94.         stage('Build') {
  95.             options {
  96.                 timestamps()
  97.             }
  98.             steps {
  99.                 script {
  100.                     if (fileExists('./build-carbon-ui') && skipBuild) {
  101.                         currentBuild.currentResult = 'SUCCESS'
  102.                         return
  103.                     }
  104.  
  105.                     // build carbon-ui in directory ./build-carbon-ui
  106.                 }
  107.             }
  108.         }
  109.  
  110.         stage('Unit tests') {
  111.             steps {
  112.                 script {
  113.                     if (skipUnitTests) {
  114.                         currentBuild.currentResult = 'SUCCESS'
  115.                         return
  116.                     }
  117.                 }
  118.             }
  119.         }
  120.  
  121.         stage('Integration tests') {
  122.             steps {
  123.                 script {
  124.                     if (skipIntegrationTests) {
  125.                         currentBuild.currentResult = 'SUCCESS'
  126.                         return
  127.                     }
  128.                 }
  129.             }
  130.         }
  131.  
  132.         stage('UI tests') {
  133.             options {
  134.                 timestamps()
  135.             }
  136.             steps {
  137.                 script {
  138.                     if (skipUiTests) {
  139.                         currentBuild.currentResult = 'SUCCESS'
  140.                         return
  141.                     }
  142.                 }
  143.             }
  144.         }
  145.  
  146.         stage('Rate build') {
  147.             steps {
  148.                 script {
  149.                     if (skipRating) {
  150.                         currentBuild.currentResult = 'SUCCESS'
  151.                         return
  152.                     }
  153.                 }
  154.             }
  155.         }
  156.  
  157.     }
  158.  
  159.     post {
  160.         always {
  161.             echo 'Post -> always section'
  162.             echo "Build status: ${currentBuild.result}"
  163.         }
  164.     }
  165.  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement