1 // inspired/copied from https://github.com/liejuntao001/jenkins-k8sagent-lib
3 import org.wamblee.jenkins.pipelinelib.MyYaml
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
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.
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
18 version: env.BRANCH_NAME,
19 repo: env.CONTAINER_REGISTRY,
20 label: env.STAGE_NAME ? env.STAGE_NAME: env.JOB_NAME,
22 defaultContainer: null // initialized to first container later on
24 args.label = env.JOB_NAME
26 args.label = args.label + "-" + env.STAGE_NAME
28 args = defaults << args
30 // combine the configured application templates
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
36 if (!args.defaultContainer) {
37 args.defaultContainer = containers[0]
39 containers = containers.plus(0, 'jnlp')
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}'")
46 // all args are available to the templates
47 Map template_vars = args
50 for (container in containers ) {
51 template = libraryResource 'podtemplates/' + container + '.yaml'
52 template = renderTemplate(template, template_vars)
53 templates.add(template)
56 def myyaml = new MyYaml()
57 def final_template = myyaml.merge(templates)
60 ret.idleMinutes = args.idleMinutes
61 ret.label = args.label
62 ret.yaml = final_template
63 ret.defaultContainer = args.defaultContainer
65 println('agentsetup: parameters returned' + ret);