I am trying to use environment variables defined outside of any node in a Jenkins file. I can bring them into scope at any stage of the pipeline in any node, but not inside the function. The only solution I can think of right now is to pass them as parameters. But I would like to refer to env variables directly inside the function, so I don't need to pass so many parameters. Here is my code. How can I get a function to output the correct BRANCH_TEST value?
def BRANCH_TEST = "master" node { deploy() } def deploy(){ echo BRANCH_TEST }
Jenkins console output:
[Pipeline] [Pipeline] echo null [Pipeline] } [Pipeline]
source share