removed override for jnlp
[pipelinelib] / vars / agentsetup.groovy
1 // inspired/copied from https://github.com/liejuntao001/jenkins-k8sagent-lib
2
3 import org.wamblee.jenkins.pipelinelib.MyYaml
4
5 // containers: comma-separated list of containers to include. The order of the containers i 
6 //    important. Each container in the list corresponds to a yaml file in the podtemplates resource
7 //    resource directory. 
8 // repo: docker repo, default is the repo configured in the CONTAINER_REGISTRY environment variable
9 // version: version to use, defaults to BRANCH_NAME 
10 // label: label to use for the agent. Defaults to the stage name if the agent is configured within a stage,
11 //      otherwise the job name is used. 
12 //
13 // All of the arguments specified in the call to agentsetup are passed without change to the 
14 // pod template files and can be accessed in the yaml file as ${name} where name is the 
15 // argument name. 
16 def call(Map args) { 
17   def defaults = [ 
18     version: env.BRANCH_NAME,
19     repo: env.CONTAINER_REGISTRY,
20     label: env.STAGE_NAME ? env.STAGE_NAME: env.BUILD_TAG,
21     idleMinutes: 0,
22     defaultContainer: null // initialized to first container later on
23   ]
24   args.label = env.BUILD_TAG
25   if (env.STAGE_NAME) { 
26     args.label = args.label + "-" + env.STAGE_NAME
27   } 
28   args = defaults << args
29     
30   // combine the configured application templates 
31   
32   def containers = args.containers.split(',').toList()
33   // always include the jnlp container to increase resource requirements.
34   // Otherwise, the checkout will be slow because of the limite amount of cpu that is 
35   // reserverd. 
36   if (!args.defaultContainer) { 
37     args.defaultContainer = containers[0]
38   }
39   //containers = containers.plus(0, 'jnlp')
40   
41   args.label = args.label.toLowerCase().replaceAll("[^a-zA-Z0-9]", "-").replaceAll("-+", "-")
42   println("agentsetup: containers to include: " + containers)
43   println("agentsetup: label '${args.label}'")
44   
45   
46   // all args are available to the templates 
47   Map template_vars = args
48   
49   def templates = []
50   for (container in containers ) { 
51     template = libraryResource 'podtemplates/' + container + '.yaml'
52     template = renderTemplate(template, template_vars)
53     templates.add(template)
54   }
55
56   def myyaml = new MyYaml()
57   def final_template = myyaml.merge(templates)
58
59   ret = [:]
60   ret.idleMinutes = args.idleMinutes
61   ret.label = args.label  
62   ret.yaml = final_template
63   ret.defaultContainer = args.defaultContainer
64   
65   println('agentsetup: parameters returned' + ret); 
66   
67   ret 
68                       
69 }