简体   繁体   中英

In Jenkins Pipeline return a value ( map or list ) from shared library in vars folder

I have a Jenkins Pipeline which invokes a groovy function inside vars folder.

a) Is it a right approach to return a value , say a list or map from the script and access it in the pipeline

b) Even if its not the right approach is there a way to achieve this functionality?

For utility functions I would use the src folder, however I don't see a reason why it shouldn't work with the vars folder.

From within Jenkinsfile call: def result = yourClass{ yourArg } and add a return value to the definition if vars like: def call(body) { return true }

Yes, there is nothing wrong with that approach. Many method calls in shared libraries return values to be manipulated in the pipeline.

You return the value just like you would for any other method call. In a declarative pipeline, you can't assign that return value to anything unless you are in a script{} tag. But you could always use a GString to print it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM