[~/git/learn-jjb/jjb1] [my-venv] $ cat *yml- job:name: job-namebuilders:- shell: !include shell.sh[~/git/learn-jjb/jjb1] [my-venv] $ cat *sh#!/bin/bash -e
[~/git/learn-jjb/jjb1] [my-venv] $ jenkins-jobs test . 2>/dev/null | grep 'command>'<command>echo hello world echo hello world</command>[~/git/learn-jjb/jjb1] [my-venv] $
[~/git/learn-jjb/jjb1] [my-venv] $ cat *yml- job:name: job-namebuilders:- shell: |!include shell.sh[~/git/learn-jjb/jjb1] [my-venv] $ jenkins-jobs test . 2>/dev/null | grep -A1 '<command>'<command>!include shell.sh</command>[~/git/learn-jjb/jjb1] [my-venv] $
/tmp/jenkins7912277661751964409.sh: line 28: ${{GIT_REPOSITORIES_LIST//\'/\"}}: bad substitution
Aleksey Tsalolikhin Sr. Systems Engineer |
I finally got this change socialized and merged. I'm a little confused as I thought that if I used "!include-raw", I would have to escape my Make-style shell variables to keep JJB away from trying to expand the contents of the braces -- for example, I tested and confirmed that if I had
echo {fruit}
in my included shell script, and I had a variable "fruit" in the JJB project set to "banana", I would see "banana" in the shell script output in the Jenkins build log
Hello,
!include-raw reads the text from the file and injects it as yaml, it is then treated exactly as is without any specific escaping. Since JJB uses curly braces to delimit variables, {fruit} is expanded when in a job template. If you wanted the job to contain literally {fruit} without any expansion by jjb, you need the !include-raw-escape which would escape the curly brace from the source file by doubling them.
Assuming a script echo.sh having:
repos=${GIT_REPO:-}
echo '{fruit}'
I ) In a job
!include-raw-escape: echo.sh gives:
<command>repos=${{GIT_REPO:-}}
echo '{{fruit}}'
</command>
The curly braces have been escaped by doubling them.
On the other hand, !include-raw: echo.sh gives the expected
output:
<command>repos=${GIT_REPO:-}
echo '{fruit}'
</command>
That is because a job does not do any interpolation of the curly braces.
II ) in a job-template
!include-raw-escape: echo.sh gives what you are looking for:
<command>repos=${GIT_REPO:-}
echo '{fruit}'
</command>
The curly braces have been escaped and they are not expanded to variable by the template.
!include-raw: echo.sh yields an error. The template is unable to be formatted, it is missing the GIT_REPO and fruit variables.
In conclusion:
In a JOB use include-raw
In a TEMPLATE use include-raw-escape
Which also mean that builders macro can not be reused between
jobs and templates. I got almost everything to use job templates
for consistency and avoiding surprises.
The documentation might require some improvement here and there.
I will be more than happy to approve any such change ;)
Antoine "hashar" Musso
Release Engineering
Wikimedia Foundation
--
You received this message because you are subscribed to the Google Groups "jenkins-job-builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-bui...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkins-job-builder/CAGG6SKTLyLRRYyJcbk04k476Zmkn7MnQUxOa-Zv1XYtr4CEx9g%40mail.gmail.com.