How to define and use function inside Jenkins Pipeline config?

@dr-eel Don't go back and edit the question, especially when an existing answer (see the one from @jon-s) refers to the mistakes in it, as it loses context. I have reverted your change because of this reason only. As for your improvement of using the default parameter [:] , suggest that as a comment to the answer from @jon-s or even improve the answer by editing it.

Commented May 25, 2018 at 7:21

1 Answer 1

First off, you shouldn't add $ when you're outside of strings ( $class in your first function being an exception), so it should be:

def doCopyMibArtefactsHere(projectName) < step ([ $class: 'CopyArtifact', projectName: projectName, filter: '**/**.mib', fingerprintArtifacts: true, flatten: true ]); >def BuildAndCopyMibsHere(projectName, params) < build job: project, parameters: params doCopyMibArtefactsHere(projectName) >. 

Now, as for your problem; the second function takes two arguments while you're only supplying one argument at the call. Either you have to supply two arguments at the call:

. node < stage('Prepare Mib')< BuildAndCopyMibsHere('project1', null) >> 

. or you need to add a default value to the functions' second argument:

def BuildAndCopyMibsHere(projectName, params = null)