github.com/vmware/go-vcloud-director/v2@v2.24.0/support/Jenkinsfile (about)

     1  // Jenkins multi-branch pipeline build script. 
     2  //
     3  // Requirements:
     4  // * At least one executor node labeled 'docker' with 
     5  //   support for building and running Docker containers.
     6  // * A Jenkins file-type credential named 'go-vcloud-director-connection'
     7  //   with the contents of a GOVCD_CONFIG file.
     8  
     9  // Global variable to hold methods from the 'lib.groovy' file. 
    10  externalMethods = null
    11  
    12  // Pipeline definition.
    13  pipeline {
    14      agent { 
    15          node { 
    16              // Label on Jenkins node that runs this test. 
    17              label 'docker'
    18          }
    19      }
    20      environment {
    21          DEFAULT_GOVCD_CONFIG_CREDENTIALS_ID = 'go-vcloud-director-connection'
    22      }
    23      parameters {
    24          string(name: 'GOVCD_CONFIG_CREDENTIALS_ID', defaultValue: 'Default',
    25              description: 'A Jenkins file-type credential ID with the contents of a GOVCD_CONFIG file.'
    26          )
    27          string(name: 'OVERRIDE_GIT_REPOSITORY', defaultValue: '',
    28              description: 'The full git repository URL to clone from instead of the default.'
    29          )
    30          string(name: 'OVERRIDE_GIT_TREEISH', defaultValue: '',
    31              description: 'The branch name or commit SHA to test from OVERRIDE_GIT_REPOSITORY.'
    32          )
    33          string(name: 'OVERRIDE_GIT_CREDENTIALS_ID', defaultValue: '',
    34              description: 'A Jenkins credential ID to use when cloning from OVERRIDE_GIT_REPOSITORY.'
    35          )
    36          text(name: 'GOVCD_CONFIG_CONTENTS', defaultValue: '',
    37              description: 'The contents of a GOVCD_CONFIG file to use for samples and system tests.'
    38          )
    39      }
    40      stages {
    41          stage('checkout') {
    42              steps {
    43                  script {
    44                      // Remove and checkout current branch from git using built-in
    45                      // Jenkins commands exposed in groovy. Use parameters to determine
    46                      // if a different git repo or branch should be checked out and tested.
    47                      deleteDir()
    48  
    49                      def overrideGit = false
    50                      if (params.OVERRIDE_GIT_REPOSITORY != null) {
    51                          if (params.OVERRIDE_GIT_REPOSITORY != '') {
    52                              overrideGit = true
    53                          }
    54                      }
    55  
    56                      if (overrideGit == false) {
    57                          checkout scm
    58                      } else {
    59                          def gitTreeish = params.OVERRIDE_GIT_TREEISH
    60                          def gitRemoteConfig = [:]
    61                          gitRemoteConfig['url'] = params.OVERRIDE_GIT_REPOSITORY
    62  
    63                          if (params.OVERRIDE_GIT_CREDENTIALS_ID != '') {
    64                              gitRemoteConfig['credentialsId'] = params.OVERRIDE_GIT_CREDENTIALS_ID
    65                          }
    66                          
    67                          checkout([
    68                              $class: 'GitSCM',
    69                              branches: [[name: gitTreeish]],
    70                              userRemoteConfigs: [gitRemoteConfig]
    71                          ])
    72                      }
    73  
    74                      // Print configuration for later debugging. 
    75                      sh "git config --list"
    76                      sh "git branch"
    77                  }
    78              }
    79          }
    80          stage('prepare') {
    81              steps {
    82                  script {
    83                      // All code is available now, load the methods to do real work
    84                      externalMethods = load 'support/lib.groovy'
    85                  }
    86              }
    87          }
    88          stage('build') {
    89              steps {
    90                  script {
    91                      // Run this method from the lib.groovy file
    92                      externalMethods.build()
    93                  }
    94              }
    95          }
    96      }
    97      post { 
    98          failure { 
    99              echo "Job failed! System test environment will not be cleared."
   100              script {
   101                  if (externalMethods != null) {
   102                      // Run this method from the lib.groovy file
   103                      externalMethods.cleanupWorkspace()
   104                  }
   105              }
   106          }
   107          success { 
   108              echo "Job succeeded! Cleaning up system test environment"
   109              script {
   110                  if (externalMethods != null) {
   111                      // Run these methods from the lib.groovy file
   112                      externalMethods.cleanupWorkspace()
   113                  }
   114              }
   115          }
   116      }
   117  }