// inspired/copied from https://github.com/liejuntao001/jenkins-k8sagent-lib import org.wamblee.jenkins.pipelinelib.MyYaml // containers: comma-separated list of containers to include. The order of the containers i // important. Each container in the list corresponds to a yaml file in the podtemplates resource // resource directory. // repo: docker repo, default is the repo configured in the CONTAINER_REGISTRY environment variable // version: version to use, defaults to BRANCH_NAME // label: label to use for the agent. Defaults to the stage name if the agent is configured within a stage, // otherwise the job name is used. // // All of the arguments specified in the call to agentsetup are passed without change to the // pod template files and can be accessed in the yaml file as ${name} where name is the // argument name. def call(Map args) { def defaults = [ version: env.BRANCH_NAME, repo: env.CONTAINER_REGISTRY, label: env.STAGE_NAME ? env.STAGE_NAME: env.BUILD_TAG, idleMinutes: 0, defaultContainer: null // initialized to first container later on ] args.label = env.BUILD_TAG if (env.STAGE_NAME) { args.label = args.label + "-" + env.STAGE_NAME } args = defaults << args // combine the configured application templates def containers = args.containers.split(',').toList() // always include the jnlp container to increase resource requirements. // Otherwise, the checkout will be slow because of the limite amount of cpu that is // reserverd. if (!args.defaultContainer) { args.defaultContainer = containers[0] } //containers = containers.plus(0, 'jnlp') args.label = args.label.toLowerCase().replaceAll("[^a-zA-Z0-9]", "-").replaceAll("-+", "-") println("agentsetup: containers to include: " + containers) println("agentsetup: label '${args.label}'") // all args are available to the templates Map template_vars = args def templates = [] for (container in containers ) { template = libraryResource 'podtemplates/' + container + '.yaml' template = renderTemplate(template, template_vars) templates.add(template) } def myyaml = new MyYaml() def final_template = myyaml.merge(templates) ret = [:] ret.idleMinutes = args.idleMinutes ret.label = args.label ret.yaml = final_template ret.defaultContainer = args.defaultContainer println('agentsetup: parameters returned' + ret); ret }