@David can you please elaborate what do you mean by main body of the script 
?

I did try adding print statements to see if it is getting there. All the 
code samples i have pasted in my post would result in successful execution 
but no output, even when i have some in the function. Not sure what is 
wrong.


On Tuesday, 21 March 2017 20:34:12 UTC+1, David Karr wrote:
>
> On Tue, Mar 21, 2017 at 10:02 AM, ishan jain <[email protected] 
> <javascript:>> wrote: 
> > Probably i am being silly, but seriously i am not able to call a 
> function 
> > which i have defined in my Jenkinsfile from within a step. Here is a 
> sample: 
> > 
> > def meta = "something" 
> > 
> > stage (build) { 
> > 
> >       buildProject(meta) 
> > } 
> > 
> > def buildProject(meta) { 
> > return { 
> >       node { 
> >           //whatever i need to do 
> >       } 
> >   } 
> > } 
>
> I might be wrong, but I don't believe you can use the "node" or 
> "stage" DSL anywhere but in the main body of the script. 
>
> > This simply does not do anything. I tried various combos to try n call 
> it, 
> > but nothing. How exactly should i call a function ? 
>
> Calling a function is simple.  Did you try having the function just do 
> a "println" or "echo" to verify that it got there?  If you see that, 
> then move on to more complex functionality. 
>
> > def meta = "something" 
> > 
> > stage (build) { 
> >       node { 
> >       buildProject(meta) 
> >   } 
> > } 
> > 
> > def buildProject(meta) { 
> > return { 
> > 
> >           //whatever i need to do 
> > 
> >   } 
> > } 
> > 
> > 
> > 
> > def meta = "something" 
> > 
> > stage (build) { 
> >       step { 
> >       buildProject(meta) 
> >      } 
> > } 
> > 
> > def buildProject(meta) { 
> > return { 
> >       node { 
> >           //whatever i need to do 
> >       } 
> >   } 
> > } 
> > 
> > 
> > 
> > def meta = "something" 
> > 
> > stage (build) { 
> > 
> >       def output =  buildProject(meta) 
> > } 
> > 
> > def buildProject(meta) { 
> > return { 
> >       node { 
> >           //whatever i need to do 
> >       } 
> >   } 
> > } 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Jenkins Users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/jenkinsci-users/1cf8438c-7bc4-44f6-9e1d-3f42ee863de2%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/a11f106d-2db1-4d57-94ba-6213e9430342%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to