Comment puis-je appeler un script groovy à partir d'un Jenkins fichier?

Je suis en train d'essayer de séparer le contenu d'un Jenkinsfile dans un script groovy à faire. Mais il ne parvient pas à appeler ces scripts:
Voici le code:

#!/usr/bin/env groovy

node('test-node'){

  stage('Checkout') {
    echo "${BRANCH_NAME} ${env.BRANCH_NAME}"
    scm Checkout

  }

  stage('Build-all-targets-in-parallel'){

    def workspace = pwd()
    echo workspace
    parallel(
      'first-parallel-target' :
       {
         //Load the file 'file1.groovy' from the current directory, into a variable called "externalMethod".
         //callScriptOne()
         def externalMethod = load("file1.groovy")
         //Call the method we defined in file1.
          externalMethod.firstTest()
       },
       'second-parallel-target' :
      {
         //callScriptTwo()
         def externalMethod = load("file2.groovy")
         //Call the method we defined in file1.
         externalMethod.testTwo()
        }
    )
  }
  stage('Cleanup workspace'){
    deleteDir()
  }
}

fichier.groovy

#!groovy

def firstTest(){

  node('test-node'){
    
    stage('build'){
      echo "Second stage"
    }
    
    stage('Cleanup workspace'){
      deleteDir()
    }
  }
}

Ressemble à la Jenkinsfile est en mesure d'appeler fichier1.groovy mais me donne toujours une erreur:

java.lang.NullPointerException: Cannot invoke method firstTest() on null object
  • Je ne pense pas que load("file1.groovy") est de trouver votre groovy fichier essayez de déboguer que.
InformationsquelleAutor user_dev | 2017-04-10