Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * defaultParametersForGerritEvent Map default parameters for the Build in case if build is triggered by Gerrit event.
- * This will override parameters existing in params.XXX
- */
- Map defaultParametersForGerritEvent = [
- SKIP_BUILD: true,
- SKIP_UNIT_TESTS: false,
- SKIP_INTEGRATION_TESTS: false,
- SKIP_UI_TESTS: true,
- SKIP_RATING: true
- ]
- boolean skipBuild, skipUnitTests, skipIntegrationTests, skipUiTests, skipRating
- pipeline {
- agent { label 'vm8-linux' }
- parameters {
- choice(name: 'INVOKE_PARAMETERS', choices: "Yes\nNo")
- booleanParam(name: 'SKIP_BUILD', defaultValue: false)
- booleanParam(name: 'SKIP_UPLOAD', defaultValue: true)
- booleanParam(name: 'SKIP_UNIT_TESTS', defaultValue: false)
- booleanParam(name: 'SKIP_INTEGRATION_TESTS', defaultValue: false)
- booleanParam(name: 'SKIP_UI_TESTS', defaultValue: true)
- booleanParam(name: 'SKIP_RATING', defaultValue: true)
- }
- stages {
- stage('Initialization') {
- steps {
- script {
- switch (env.GERRIT_EVENT_TYPE) {
- case [null, '']:
- echo 'Job has been triggered via Web'
- break
- case 'patchset_created':
- echo "Job has been triggered by the new patchset in Gerrit. Url is ${env.GERRIT_PATCHSET_URL}"
- break
- case 'comment added':
- echo "Job has been triggered by comment ${env.GERRIT_COMMENT} in Gerrit. Url is ${env.GERRIT_PATCHSET_URL}"
- break
- default:
- echo 'Job has been triggered by unknown reason'
- break
- }
- sh '''
- echo "Hostname: $(hostname)"
- echo "Environment variables"
- printenv | sort
- echo "Working directory: $(pwd)"
- tree -d
- '''
- if (params.INVOKE_PARAMETERS == 'Yes' && !env.GERRIT_EVENT_TYPE) {
- currentBuild.result = 'FAILED'
- error 'Parameters have been invoked! Aborted.'
- }
- skipBuild = env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_BUILD : params.SKIP_BUILD
- skipUnitTests = env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_UNIT_TESTS : params.SKIP_UNIT_TESTS
- skipIntegrationTests = env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_INTEGRATION_TESTS : params.SKIP_INTEGRATION_TESTS
- skipUiTests = env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_UI_TESTS : params.SKIP_UI_TESTS
- skipRating = env.GERRIT_EVENT_TYPE ? defaultParametersForGerritEvent.SKIP_RATING : params.SKIP_RATING
- }
- }
- }
- stage('Fetch carbon-ui') {
- steps {
- sh """#!/usr/bin/env bash
- if [[ "$(git -C ./carbon-ui rev-parse --is-inside-work-tree 2> /dev/null)" == "true" ]]
- then
- git -C ./carbon-ui clean --force -d -x
- git -C ./carbon-ui reset --hard --recurse-submodules
- git -C ./carbon-ui checkout --recurse-submodules develop
- git -C ./carbon-ui pull --recurse-submodules
- else
- git clone --recurse-submodules ssh://gerritSunnyvale/carbon-ui
- fi
- """
- }
- }
- stage('Build') {
- options {
- timestamps()
- }
- steps {
- script {
- if (fileExists('./build-carbon-ui') && skipBuild) {
- currentBuild.currentResult = 'SUCCESS'
- return
- }
- // build carbon-ui in directory ./build-carbon-ui
- }
- }
- }
- stage('Unit tests') {
- steps {
- script {
- if (skipUnitTests) {
- currentBuild.currentResult = 'SUCCESS'
- return
- }
- }
- }
- }
- stage('Integration tests') {
- steps {
- script {
- if (skipIntegrationTests) {
- currentBuild.currentResult = 'SUCCESS'
- return
- }
- }
- }
- }
- stage('UI tests') {
- options {
- timestamps()
- }
- steps {
- script {
- if (skipUiTests) {
- currentBuild.currentResult = 'SUCCESS'
- return
- }
- }
- }
- }
- stage('Rate build') {
- steps {
- script {
- if (skipRating) {
- currentBuild.currentResult = 'SUCCESS'
- return
- }
- }
- }
- }
- }
- post {
- always {
- echo 'Post -> always section'
- echo "Build status: ${currentBuild.result}"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement