1

How to call a groovy function from a Jenkinsfile?

 
Essentially, I have a declarative pipeline where I am trying to load a .groovy file and call a function defined in it.
The function makes a node call (that uses mustache to replace some placeholder values with actual values and generate a file based on it).
 
This however fails. Even an echo call from the function fails, with "java.lang.NullPointerException: Cannot invoke method generateManifest() on null object". I have no idea why.
 
Any tips are more than welcome!

1 comment

  • 0
    Avatar
    Carlos Rodriguez Lopez

    Please, have a look at the following example for loading files, it is not for declarative pipelines but it could be a good starting point. Have a look at the files that are being loaded are in the same directory.

    Validate those steps with the Snippet Generator to verify that they are valid in your environment.

    Assuming that deployer.groovy file is in the current directory with your Jenkinsfile

    Change 

    deployer = fileLoader.load ('deployer')
    

    For 

    deployer = load ('deployer.groovy')
    Edited by Carlos Rodriguez Lopez
Please sign in to leave a comment.