--- /dev/null
+// 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.JOB_NAME,
+ ]
+ if (!args) {
+ args = [:]
+ }
+ args.label = env.JOB_NAME
+ if (env.STAGE_NAME) {
+ args.label = args.label + "-" + env.STAGE_NAME
+ }
+ args = defaults << args
+
+ // combine the configured application templates
+ args.label = args.label.toLowerCase().replaceAll("[^a-zA-Z0-9]", "-").replaceAll("-+", "-")
+
+
+ command = ""
+
+ command += '''
+ files="$( find . -name '*.template' )"
+ for file in $files
+ do
+ base="$( dirname "$file")/$( basename "$file" .template )"
+ cat "$file" '''
+
+ for (key in args.keySet()) {
+ command += """ | sed 's|\\\$${key}|${args[key]}|g' """
+ }
+
+ command += ''' > "$file.tmp"
+ mv "$file.tmp" "$base"
+ done
+ '''
+
+ println "processresources: ${args}"
+ println "processresources: $command"
+
+ sh "$command"
+
+}