13

I have followed jenkins extending pipeline with shared libraries
it was mentioned that

The src directory should look like standard Java source directory structure. This directory is added to the classpath when executing Pipelines.

while the vars directory hosts scripts that define global variables accessible from Pipeline

Note: I am more curious about the difference in usage not in implementation.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Monem
  • 255
  • 2
  • 15

1 Answers1

2

Ok, well, you can see some sample differences in usage by simply examining the samples on the Extending with Shared Libraries page that you've probably already seen. For instance, if you look for the "Zot.groovy" example, you'll see that the code that uses this has to "new" the "Zot" class. However, if you look at the "vars/acme.groovy" sample, you'll see that the user code doesn't have to "new" anything, because the global variable named "acme" exists to be referenced by the script.

There are other differences, but that's one simple contrast.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • 3
    thanks, i think that goes with what they mentioned that vars are being treated as singletons, they are also easier to deal with without needing to explicitly pass steps/env .. but i am still wondering what the usage of src classes can add to the process that global vars can't do? – Monem Feb 11 '17 at 08:29
  • Uh, the ability to create multiple instances of them? – David M. Karr Feb 11 '17 at 17:51
  • 1
    But you can also create a class inside the src, with a static method, meaning it is available without creating an instance... – Swifting Sep 14 '17 at 07:51