How to define global variables in groovy file, which I want to load and consume?

7,243

try this one

static void main(String[] args) { 
      // Initializing 2 variables 
      def x = 5; 
      def y = 10;

      //Performing addition of 2 operands 
      println(x+y);
 }

}

check this URL

Share:
7,243

Related videos on Youtube

omkar sirra
Author by

omkar sirra

Updated on September 18, 2022

Comments

  • omkar sirra
    omkar sirra over 1 year

    I have a Jenkins parent groovy file which consumes the child groovy file

    Parent grooy file:

    ...
    def child = load 'child-groovy-file';
    child.execute();
    

    Child groovy file:

    a = "first letter";
    b = "second letter;
    def execute
    {
    echo "a is "+a;
    ...
    }
    

    But this is not working. Unable to access variables, which are defined in Child Groovy file, when trying to access from Parent groovy file. When I create a node block and trying to consume directly the child groovy file, It is working.

    Is the Environment variables only the solution to access globally?