Running externally loaded groovy functions on agent

52 views
Skip to first unread message

Fahd Arshad

unread,
Oct 13, 2016, 2:04:50 PM10/13/16
to Jenkins Users
Hi Guys,

I need Some help loading external functions in Jenkinsfile.

Jenkinsfile contents below:
node('local-node')

{

git "https://github.com/afahd/MW.git"
echo "this is groovy"
clone.clone()

}

Externally loaded function:





@Grab(group='org.yaml', module='snakeyaml', version='1.17')
import org.yaml.snakeyaml.*
public class Dependency {
   public LinkedHashMap h1;
   Dependency(LinkedHashMap h1) {
       this.h1 = h1
   }
}
def clone()
{
  Yaml yaml = new Yaml();
  String project;
  String location;
  String branch;
  String build;
  InputStream input = new FileInputStream(new File("dependencies.yaml"));
  Dependency data = yaml.load(input);
  Set s1 = data.h1.keySet();
  for (int num=0;num<s1.size();num++)
  {
      project = s1.toArray()[num];
      location = data.h1.get(project)['location'];
      branch = data.h1.get(project)['branch'];
      build = data.h1.get(project)['build'];
      echo "Cloning dependencies for $project "
      git branch: branch, url: location
   }
}
return this;

When i call clone.clone() the function gets executed on the master node not the 'local-node'. 

Reply all
Reply to author
Forward
0 new messages