diff --git a/resources/podtemplates/doxygen.yaml b/resources/podtemplates/doxygen.yaml index 4718d9f..411e851 100644 --- a/resources/podtemplates/doxygen.yaml +++ b/resources/podtemplates/doxygen.yaml @@ -1,7 +1,8 @@ spec: containers: - name: doxygen - image: hrektts/doxygen:latest + image: ${TEMPLATE_DOXYGEN_IMAGE} + #image: hrektts/doxygen:latest # better to use your own #image: docker.example.com/doxygen:v1.0.0 tty: true \ No newline at end of file diff --git a/test/groovy/K8sAgentTest.groovy b/test/groovy/K8sAgentTest.groovy index 52d21e5..d876f5b 100644 --- a/test/groovy/K8sAgentTest.groovy +++ b/test/groovy/K8sAgentTest.groovy @@ -265,6 +265,35 @@ metadata: image: hrektts/doxygen:latest tty: true""" + def small_doxygen_external_yaml = """spec: + hostAliases: + - ip: "192.168.1.15" + hostnames: + - "jenkins.example.com" + volumes: + - hostPath: + path: /data/jenkins/repo_mirror + type: "" + name: volume-0 + containers: + - name: jnlp + image: jenkinsci/jnlp-slave:3.29-1 + imagePullPolicy: Always + command: + - /usr/local/bin/jenkins-slave + volumeMounts: + - mountPath: /home/jenkins/repo_cache + name: volume-0 + resources: + limits: + memory: 8Gi + requests: + memory: 4Gi + cpu: 2 + - name: doxygen + image: hrektts/doxygen:my_test_version + tty: true""" + def selector_yaml = """spec: hostAliases: - ip: "192.168.1.15" @@ -314,6 +343,9 @@ metadata: agent = loadScript("vars/k8sagent.groovy") parser = new MyYaml() + helper.registerAllowedMethod('renderTemplate', [String, Map]) { s,opts -> + loadScript("vars/renderTemplate.groovy")(s, opts) + } } @Test @@ -445,6 +477,25 @@ metadata: //assertEquals "results", expected.entrySet(), ret.entrySet() } + @Test + void testDoxygenExternalVersion() { + + binding.setVariable('TEMPLATE_DOXYGEN_IMAGE', "hrektts/doxygen:my_test_version") + + def expected_yaml = small_doxygen_external_yaml + def processed_yaml = parser.merge([expected_yaml.toString()]) + + def expected = [ + cloud: 'kubernetes', + yaml : processed_yaml + ] + + def ret = agent(name: 'small+doxygen') + + assertEquals "results", ret.entrySet().containsAll(expected.entrySet()), true + //assertEquals "results", expected.entrySet(), ret.entrySet() + } + @Test void testNoSelector() { def expected_yaml = base_yaml diff --git a/vars/k8sagent.groovy b/vars/k8sagent.groovy index 277e952..63d9c93 100644 --- a/vars/k8sagent.groovy +++ b/vars/k8sagent.groovy @@ -12,6 +12,18 @@ def call(Map opts = [:]) { String nodeSelector = opts.get('selector', '') String jnlpImage = opts.get('jnlpImage', '') + String doxygen_image + + try { + doxygen_image = "${TEMPLATE_DOXYGEN_IMAGE}" + } catch (e) { + //println("TEMPLATE_DOXYGEN_IMAGE not defined") + doxygen_image = 'hrektts/doxygen:latest' + } + + Map template_vars = [:] + template_vars['TEMPLATE_DOXYGEN_IMAGE'] = doxygen_image + def ret = [:] def comps = name.split('\\+|-').toList() @@ -24,6 +36,7 @@ def call(Map opts = [:]) { String template for (c in comps) { template = libraryResource 'podtemplates/' + c + '.yaml' + template = renderTemplate(template, template_vars) templates.add(template) } @@ -46,6 +59,8 @@ spec: templates.add(baseImage) } + + def myyaml = new MyYaml() def final_template = myyaml.merge(templates) diff --git a/vars/renderTemplate.groovy b/vars/renderTemplate.groovy new file mode 100644 index 0000000..a230bb3 --- /dev/null +++ b/vars/renderTemplate.groovy @@ -0,0 +1,6 @@ +import groovy.text.StreamingTemplateEngine + +def call(input, variables) { + def engine = new StreamingTemplateEngine() + return engine.createTemplate(input).make(variables).toString() +}