|
| 1 | +#!/usr/bin/env groovy |
| 2 | +@Library('apm@current') _ |
| 3 | + |
| 4 | +pipeline { |
| 5 | + agent { label 'linux && immutable' } |
| 6 | + environment { |
| 7 | + BASE_DIR = 'src/github.com/elastic/opbeans-frontend' |
| 8 | + NOTIFY_TO = credentials('notify-to') |
| 9 | + JOB_GCS_BUCKET = credentials('gcs-bucket') |
| 10 | + JOB_GCS_CREDENTIALS = 'apm-ci-gcs-plugin' |
| 11 | + DOCKERHUB_SECRET = 'secret/apm-team/ci/elastic-observability-dockerhub' |
| 12 | + PIPELINE_LOG_LEVEL = 'INFO' |
| 13 | + } |
| 14 | + options { |
| 15 | + timeout(time: 1, unit: 'HOURS') |
| 16 | + buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30')) |
| 17 | + timestamps() |
| 18 | + ansiColor('xterm') |
| 19 | + disableResume() |
| 20 | + durabilityHint('PERFORMANCE_OPTIMIZED') |
| 21 | + rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) |
| 22 | + quietPeriod(10) |
| 23 | + } |
| 24 | + parameters { |
| 25 | + booleanParam(name: 'Run_As_Master_Branch', defaultValue: false, description: 'Allow to run any steps on a PR, some steps normally only run on master branch.') |
| 26 | + } |
| 27 | + triggers { |
| 28 | + issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*') |
| 29 | + } |
| 30 | + stages { |
| 31 | + stage('Initializing'){ |
| 32 | + agent { label 'linux && immutable' } |
| 33 | + options { skipDefaultCheckout() } |
| 34 | + environment { |
| 35 | + PATH = "${env.PATH}:${env.WORKSPACE}/bin" |
| 36 | + HOME = "${env.WORKSPACE}" |
| 37 | + } |
| 38 | + stages { |
| 39 | + /** |
| 40 | + Checkout the code and stash it, to use it on other stages. |
| 41 | + */ |
| 42 | + stage('Checkout') { |
| 43 | + steps { |
| 44 | + deleteDir() |
| 45 | + gitCheckout(basedir: "${BASE_DIR}") |
| 46 | + stash allowEmpty: true, name: 'source', useDefaultExcludes: false |
| 47 | + } |
| 48 | + } |
| 49 | + /** |
| 50 | + Build the project from code.. |
| 51 | + */ |
| 52 | + stage('Build') { |
| 53 | + steps { |
| 54 | + deleteDir() |
| 55 | + unstash 'source' |
| 56 | + dir("${BASE_DIR}"){ |
| 57 | + sh 'make build' |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + /** |
| 62 | + Execute unit tests. |
| 63 | + */ |
| 64 | + stage('Test') { |
| 65 | + steps { |
| 66 | + deleteDir() |
| 67 | + unstash 'source' |
| 68 | + dir("${BASE_DIR}"){ |
| 69 | + sh "make test" |
| 70 | + } |
| 71 | + } |
| 72 | + post { |
| 73 | + always { |
| 74 | + junit(allowEmptyResults: true, |
| 75 | + keepLongStdio: true, |
| 76 | + testResults: "${BASE_DIR}/**/junit-*.xml") |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + stage('Release') { |
| 81 | + input { |
| 82 | + message 'Should we release a new version?' |
| 83 | + ok 'Yes, we should.' |
| 84 | + parameters { |
| 85 | + string(name: 'VERSION', defaultValue: 'latest', description: 'What tag?') |
| 86 | + } |
| 87 | + } |
| 88 | + when { |
| 89 | + beforeInput true |
| 90 | + beforeAgent true |
| 91 | + allOf { |
| 92 | + anyOf { |
| 93 | + branch 'master' |
| 94 | + branch "\\d+\\.\\d+" |
| 95 | + branch "v\\d?" |
| 96 | + tag "v\\d+\\.\\d+\\.\\d+*" |
| 97 | + expression { return params.Run_As_Master_Branch } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + steps { |
| 102 | + deleteDir() |
| 103 | + unstash 'source' |
| 104 | + dir("${BASE_DIR}"){ |
| 105 | + dockerLogin(secret: "${DOCKERHUB_SECRET}", registry: 'docker.io') |
| 106 | + sh "VERSION=${VERSION} make publish" |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + post { |
| 114 | + always { |
| 115 | + notifyBuildResult() |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments