github.com/waldiirawan/apm-agent-go/v2@v2.2.2/Jenkinsfile (about)

     1  #!/usr/bin/env groovy
     2  
     3  @Library('apm@current') _
     4  
     5  pipeline {
     6    agent { label 'linux && immutable' }
     7    environment {
     8      REPO = 'apm-agent-go'
     9      BASE_DIR = "src/github.com/waldiirawan/apm-agent-go"
    10      NOTIFY_TO = credentials('notify-to')
    11      JOB_GCS_BUCKET = credentials('gcs-bucket')
    12      CODECOV_SECRET = 'secret/apm-team/ci/apm-agent-go-codecov'
    13      GO111MODULE = 'on'
    14      GOPATH = "${env.WORKSPACE}"
    15      GOPROXY = 'https://proxy.golang.org'
    16      HOME = "${env.WORKSPACE}"
    17      OPBEANS_REPO = 'opbeans-go'
    18      SLACK_CHANNEL = '#apm-agent-go'
    19    }
    20    options {
    21      timeout(time: 2, unit: 'HOURS')
    22      buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
    23      timestamps()
    24      ansiColor('xterm')
    25      disableResume()
    26      durabilityHint('PERFORMANCE_OPTIMIZED')
    27      rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
    28      quietPeriod(10)
    29    }
    30    triggers {
    31      issueCommentTrigger("(${obltGitHubComments()}|^run benchmark tests)")
    32    }
    33    parameters {
    34      string(name: 'GO_VERSION', defaultValue: "1.15.10", description: "Go version to use.")
    35      booleanParam(name: 'Run_As_Main_Branch', defaultValue: false, description: 'Allow to run any steps on a PR, some steps normally only run on main branch.')
    36      booleanParam(name: 'bench_ci', defaultValue: true, description: 'Enable benchmarks')
    37    }
    38    stages {
    39      stage('Initializing'){
    40        options { skipDefaultCheckout() }
    41        environment {
    42          GO_VERSION = "${params.GO_VERSION}"
    43          PATH = "${env.PATH}:${env.WORKSPACE}/bin"
    44        }
    45        stages {
    46          /**
    47           Checkout the code and stash it, to use it on other stages.
    48          */
    49          stage('Checkout') {
    50            options { skipDefaultCheckout() }
    51            steps {
    52              pipelineManager([ cancelPreviousRunningBuilds: [ when: 'PR' ] ])
    53              deleteDir()
    54              gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true, reference: '/var/lib/jenkins/.git-references/apm-agent-go.git')
    55              stash allowEmpty: true, name: 'source', useDefaultExcludes: false
    56            }
    57          }
    58          stage('Benchmark') {
    59            agent { label 'microbenchmarks-pool' }
    60            options { skipDefaultCheckout() }
    61            when {
    62              beforeAgent true
    63              allOf {
    64                anyOf {
    65                  branch 'main'
    66                  tag pattern: 'v\\d+\\.\\d+\\.\\d+.*', comparator: 'REGEXP'
    67                  expression { return params.Run_As_Main_Branch }
    68                  expression { return env.GITHUB_COMMENT?.contains('benchmark tests') }
    69                }
    70                expression { return params.bench_ci }
    71              }
    72            }
    73            steps {
    74              withGithubNotify(context: 'Benchmark', tab: 'tests') {
    75                deleteDir()
    76                unstash 'source'
    77                dir("${BASE_DIR}"){
    78                  sh script: './scripts/jenkins/bench.sh', label: 'Benchmarking'
    79                  dir('build') {
    80                    sendBenchmarks(file: 'bench.out', index: 'benchmark-go')
    81                    generateGoBenchmarkDiff(file: 'bench.out', filter: 'exclude')
    82                  }
    83                }
    84              }
    85            }
    86          }
    87        }
    88      }
    89    }
    90    post {
    91      cleanup {
    92        notifyBuildResult(goBenchmarkComment: true)
    93      }
    94    }
    95  }