I have a Declarative Pipeline that is increasing in size, so I want to split the logic using shared libraries. But I´m facing some issues because I must share some values between them and I can´t find the way to do it. Here are some examples of what I need to do:
Is there some way to solve this issue? I´m sure there must be something because the global/local variables scope is a foundation for coding, but I can´t find anything.
I tried using environment variables, but they can only be written in the environment clause. I know you can change them using withEnv or other environment clauses, but you cannot change the value and access to the new value in a different place, so they are more like constants that can be used in the piece of code they are populated. So I can access to environment variables with the value when they were defined, but I can´t change that value based on the current execution conditions (ex: if it must be executed in branch A or B).
Finally, I included multiple variables as input parameters for each method, and they return multiple values. It is not the best option for me, as I must pass around 10-12 variables for input and 4-5 for output, even when most of them are needed for input and output, so if I could pass them by reference to update them directly, or even better if I could access external vars inside of each method, it would be perfect, but at least it is working as required.
Thanks for your help.