1

Groovy scripting in place of shell scripting

On this page at github.com describing Best Practices:

https://github.com/jenkinsci/pipeline-examples/blob/master/docs/BEST_PRACTICES.md

Under "Groovy Gotchas" It says:

Don’t use the Groovy scripting in place of shell scripting - work coming for the ability to run a Groovy step on the node as with the normal Groovy plugin build step, but until then, shell out, even if it’s just to do sh 'groovy foo.groovy'.

What does this mean? If I have a whole bunch of groovy code running my pipeline, is this impacting my Jenkins infrastructure in some way? Some people are telling me that Groovy is being interpreted on the master, which is impacting performance. Is this true? How much of an impact can it have?

I have a Jenkinsfile that is loading a Pipeline Library, and the library has a number of utilities that contain a bunch of code that performs tasks. Is this no good? Do i have to go back to a series of shell scripts? 

Trying to debunk some naysayers, if anyone has some concrete information about why this entry is in the best practices file, please let me know!

Thanks!

 

2 comments

  • Avatar
    Owen Mehegan Official comment

    Hi Tim -

    It is true that any Groovy code you write inside a Scripted Pipeline job is always going to be run on the master. Thus, depending on what you use Groovy for, this can definitely have a negative impact on performance. It's just something that you should be aware of as a user; I think the greater point of the "keep things in shell scripts" advice is to encourage habits that farm that work out to executors. It's not a hard and fast rule, you can do what you want, but you should be aware of the implications. 

    This blog post has some more technical details and best practices for making use of Pipeline: https://jenkins.io/blog/2017/02/01/pipeline-scalability-best-practice/

    I hope this is helpful, if you have further questions feel free to ask!

  • 0
    Avatar
    Denys Digtiar

    Jenkins Pipeline does interpret all its Groovy scripts on the master. It is also not your regular Groovy runtime. It writes to the disk heavily since it tries to persist the whole state of execution for durability. Here are links that should shed more light on it:

    Scaling Pipelines

    Best Practices for Scalable Pipeline Code

Please sign in to leave a comment.