From 90663ea8a631688aa32630651828ad8b205f2dbf Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Fri, 13 Apr 2018 13:38:05 -0400 Subject: [PATCH] Document use of | character for variable defaults Change-Id: Id20fc7a49fef6684170a73834f2df06db3f0ca7f Signed-off-by: Thanh Ha --- doc/source/definition.rst | 10 +++++ .../yamlparser/fixtures/variable_defaults.xml | 39 +++++++++++++++++++ .../fixtures/variable_defaults.yaml | 16 ++++++++ 3 files changed, 65 insertions(+) create mode 100644 tests/yamlparser/fixtures/variable_defaults.xml create mode 100644 tests/yamlparser/fixtures/variable_defaults.yaml diff --git a/doc/source/definition.rst b/doc/source/definition.rst index 18485905e..ce4e86df7 100644 --- a/doc/source/definition.rst +++ b/doc/source/definition.rst @@ -474,6 +474,16 @@ For example, having a configuration file with that option enabled: Will prevent JJb from failing if there are any non-initialized variables used and replace them with the empty string instead. +.. tip:: + + Defaults for variables can be set by using the ``|`` character + ``{var|default_value}``. This is useful if we want to allow users of the + job-template to not have to pass a setting if there is a common default for + it. + + Example: + + .. literalinclude:: /../../tests/yamlparser/fixtures/variable_defaults.yaml Yaml Anchors & Aliases ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/yamlparser/fixtures/variable_defaults.xml b/tests/yamlparser/fixtures/variable_defaults.xml new file mode 100644 index 000000000..74128ad5c --- /dev/null +++ b/tests/yamlparser/fixtures/variable_defaults.xml @@ -0,0 +1,39 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo yolo + + + + + + + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo override + + + + + diff --git a/tests/yamlparser/fixtures/variable_defaults.yaml b/tests/yamlparser/fixtures/variable_defaults.yaml new file mode 100644 index 000000000..ea25c6c80 --- /dev/null +++ b/tests/yamlparser/fixtures/variable_defaults.yaml @@ -0,0 +1,16 @@ +- job-template: + name: '{name}-variable-defaults' + + builders: + - shell: '{script|echo yolo}' + +- project: + name: default + jobs: + - '{name}-variable-defaults' + +- project: + name: override + jobs: + - '{name}-variable-defaults' + script: echo override