github.com/verrazzano/verrazzano@v1.7.0/ci/ticket-commits/JenkinsfilePullRequests (about)

     1  // Copyright (c) 2021, 2022, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  pipeline {
     5      options {
     6          timestamps ()
     7      }
     8  
     9      agent {
    10         docker {
    11              image "${RUNNER_DOCKER_IMAGE}"
    12              args "${RUNNER_DOCKER_ARGS}"
    13              registryUrl "${RUNNER_DOCKER_REGISTRY_URL}"
    14              registryCredentialsId 'ocir-pull-and-push-account'
    15              label "internal"
    16          }
    17      }
    18      parameters {
    19          string (name: 'VERRAZZANO_HELPER_BRANCH',
    20                          defaultValue: 'master',
    21                          description: 'verrazzano-helper branch. master is used for 1.3+, release-1.2 is used for 1.2 and earlier, user branch name is used when testing verrazzano-helper changes',
    22                          trim: true)
    23      }
    24      environment {
    25          OCI_CLI_AUTH="api_key"
    26          OCI_CLI_TENANCY = credentials('oci-tenancy')
    27          OCI_CLI_USER = credentials('oci-user-ocid')
    28          OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint')
    29          OCI_CLI_KEY_FILE = credentials('oci-api-key')
    30          OCI_CLI_REGION = "us-phoenix-1"
    31          OCI_REGION = "${env.OCI_CLI_REGION}"
    32          OCI_OS_NAMESPACE = credentials('oci-os-namespace')
    33          OCI_OS_SHARED_BUCKET="build-shared-files"
    34      }
    35  
    36      stages {
    37          stage('Clean workspace and checkout') {
    38              environment {
    39                  GOPATH = '/home/opc/go'
    40                  GO_REPO_PATH = "${GOPATH}/src/github.com/verrazzano"
    41                  NETRC_FILE = credentials('netrc')
    42              }
    43              steps {
    44                  sh """
    45                      echo "${NODE_LABELS}"
    46                      echo "SCM checkout of ${env.GIT_BRANCH} at ${env.GIT_COMMIT}"
    47  
    48                      cp -f "${NETRC_FILE}" $HOME/.netrc
    49                      chmod 600 $HOME/.netrc
    50  
    51                      rm -rf ${GO_REPO_PATH}/verrazzano
    52                      mkdir -p ${GO_REPO_PATH}/verrazzano
    53                      tar cf - . | (cd ${GO_REPO_PATH}/verrazzano/ ; tar xf -)
    54                  """
    55                  script {
    56                      sh """
    57                          echo "Downloading verrazzano-helper from object storage"
    58                          oci --region us-phoenix-1 os object get --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_SHARED_BUCKET} --name ${params.VERRAZZANO_HELPER_BRANCH}/verrazzano-helper --file ${WORKSPACE}/verrazzano-helper
    59                          chmod uog+x ${WORKSPACE}/verrazzano-helper
    60                      """
    61                  }
    62              }
    63          }
    64  
    65          stage('Update tracking tickets with pull request') {
    66              environment {
    67                  TICKET_SERVICE_USERNAME = credentials('ticket-service-username')
    68                  TICKET_SERVICE_PASSWORD = credentials('ticket-service-password')
    69              }
    70              steps {
    71                  script {
    72                      // Do not add a comment to the tracking ticket if an existing pull request is being updated
    73                      if (currentBuild.changeSets.size() == 0) {
    74                          // Escape double quotes in the PR title
    75                          env.PR_TITLE = sh(script:'echo "${CHANGE_TITLE}" | sed \'s/"/\\\\"/g\'', returnStdout: true).trim()
    76                          sh """
    77                              ${WORKSPACE}/verrazzano-helper update ticket-commits --pr-url "${env.CHANGE_URL}" --pr-title "${env.PR_TITLE}" --pr-target "${env.CHANGE_TARGET}" --token unused --ticket-env=prod
    78                          """
    79                      } else {
    80                          echo "Existing pull request updated, skipping update of tracking ticket"
    81                      }
    82                  }
    83              }
    84          }
    85      }
    86  
    87      post {
    88          failure {
    89              script {
    90                  if (env.GIT_BRANCH == "master" || env.GIT_BRANCH ==~ "release-*" ) {
    91                      slackSend ( channel: "$SLACK_ALERT_CHANNEL", message: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}\n\n" )
    92                  }
    93              }
    94          }
    95          cleanup {
    96              deleteDir()
    97          }
    98      }
    99  }