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

     1  // This file contains methods used by Jenkinsfile to support the
     2  // Jenkins pipeline. The contents are loaded after the target
     3  // git repository is checked out.
     4  
     5  // Declare global variables so they can be used in all pipeline methods. 
     6  credentialsArray = []
     7  environmentArray = []
     8  temporaryFiles = []
     9  
    10  // Process job parameters and determine which credentials or environment
    11  // variables are required for proper processing.
    12  def init() {
    13      // Determine if a credentials ID has been provided, or if the default should be used.
    14      def govcdConfigCredentialsID = params.GOVCD_CONFIG_CREDENTIALS_ID
    15      if (govcdConfigCredentialsID.toLowerCase() == 'default') {
    16          govcdConfigCredentialsID = env.DEFAULT_GOVCD_CONFIG_CREDENTIALS_ID
    17      }
    18  
    19      // Check for a parameter containing the GOVCD_CONFIG content
    20      // Write that to a file if available, or use a Jenkins credential file
    21      if (env.GOVCD_CONFIG_CONTENTS != null && env.GOVCD_CONFIG_CONTENTS != "") {
    22          def tmpdir = pwd(tmp:true)
    23          def vcdPath = "${tmpdir}/jenkins_govcd_config"
    24  
    25          println "Write GOVCD_CONFIG_CONTENTS to ${vcdPath}"
    26          writeFile(file: vcdPath, text: env.GOVCD_CONFIG_CONTENTS)
    27          environmentArray << "GOVCD_CONFIG=${vcdPath}"
    28          temporaryFiles << vcdPath
    29      } else if (govcdConfigCredentialsID.toLowerCase() != "") {
    30          // Ensure the path to a VCD parameters file is loaded into the appropriate
    31          // environment variable for testing scripts to use.
    32          credentialsArray << [
    33              $class: 'FileBinding', 
    34              credentialsId: govcdConfigCredentialsID,
    35              variable: 'GOVCD_CONFIG'
    36          ]
    37      }
    38  }
    39  
    40  def build() {
    41      withCredentials(credentialsArray) {
    42          withEnv(environmentArray) {
    43              sh "support/run_in_docker.sh support/build.sh"
    44          }
    45      }
    46  }
    47  
    48  def cleanupWorkspace() {
    49      // Remove temporary files
    50      temporaryFiles.each {
    51          println "Remove ${it}"
    52          sh "if [ -f ${it} ]; then rm ${it}; fi"
    53      }
    54  }
    55  
    56  // Call the init method to ensure the environment and credentials are ready. 
    57  init()
    58  
    59  // Return a reference to this file to allow the pipeline to call methods. 
    60  return this