github.com/verrazzano/verrazzano@v1.7.0/ci/scan-results/JenkinsfileUpload (about)

     1  // Copyright (c) 2022, 2023, 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          skipDefaultCheckout true
     7          timestamps ()
     8      }
     9  
    10      agent {
    11          docker {
    12              image "${RUNNER_DOCKER_IMAGE}"
    13              args "${RUNNER_DOCKER_ARGS}"
    14              registryUrl "${RUNNER_DOCKER_REGISTRY_URL}"
    15              label 'internal'
    16          }
    17      }
    18  
    19      parameters {
    20          string (name: 'UPSTREAM_JOB', defaultValue: 'NONE', description: 'Name of the upstream job')
    21          string (name: 'UPSTREAM_BUILD', defaultValue: 'NONE', description: 'Build number to copy the upload file from')
    22      }
    23  
    24      environment {
    25          upload_filename = "consolidated-upload.json"
    26          copy_artifact_filter = "scan-results/latest-periodic/${upload_filename}"
    27          upload_url = "${env.SCANMANAGER_URL}"
    28          PIPELINE_OWNERS = credentials('scanning-owners')
    29      }
    30  
    31      stages {
    32          stage('Fetch Scan Report') {
    33              steps {
    34                  script {
    35                      sh """
    36                          echo "Copying ${copy_artifact_filter} from upstream pipeline"
    37                          echo "UPSTREAM_JOB = ${params.UPSTREAM_JOB}"
    38                          echo "UPSTREAM_BUILD = ${params.UPSTREAM_BUILD}"
    39                      """
    40                      copyArtifacts(
    41                          projectName: "/${params.UPSTREAM_JOB}",
    42                          selector: specific("${params.UPSTREAM_BUILD}"),
    43                          filter: "${copy_artifact_filter}",
    44                          flatten: true,
    45                          optional: false,
    46                          fingerprintArtifacts: false
    47                      )
    48                      sh """
    49                          echo "Got file ${upload_filename}:"
    50                          ls -l
    51                          head -8 ${upload_filename}
    52                      """
    53                  }
    54              }
    55          }
    56  
    57          stage("Upload Scan Report") {
    58              steps {
    59                  script {
    60                      sh '''
    61                      echo "Uploading ${upload_filename} to ${upload_url}"
    62                      uploadstatus=\$(curl -w "%{http_code}" -k -v -X POST -H "Content-Type: application/json" -d@${upload_filename} ${upload_url})
    63                      if [[ $uploadstatus -lt 400 ]];then
    64                        echo "File uploaded"
    65                      else
    66                        exit 1
    67                      fi
    68                      '''
    69                  }
    70              }
    71          }
    72  
    73      }
    74  
    75      post {
    76          failure {
    77              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\nSuspects:\n${PIPELINE_OWNERS}" )
    78          }
    79          cleanup {
    80              sh """
    81                  echo "Removing upload file ${upload_filename}"
    82                  rm -f ${upload_filename}
    83              """
    84          }
    85      }
    86  }
    87