Fix default value regex pattern

Negative values can't be set as default values
currently, for example:
num-to-keep: '{num_to_keep|-1}'
It will return an exception saying: 'parameter missing
to format'.

This should also allow other patterns as long they do
not contain the closing curly bracket.

Change-Id: I26dafb80b120f2c071dda6d9a27319d533b0f874
This commit is contained in:
Martin Kopec 2018-05-22 16:06:58 +00:00
parent f498ef4b2e
commit 1b7555309f
3 changed files with 56 additions and 1 deletions

View File

@ -85,7 +85,7 @@ class CustomFormatter(Formatter):
(?<!{){({{)* # non-pair opening {
(?:obj:)? # obj:
(?P<key>\w+) # key
(?:\|(?P<default>[\w\s]*))? # default fallback
(?:\|(?P<default>[^}]*))? # default fallback
}(}})*(?!}) # non-pair closing }
"""

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties>
<jenkins.model.BuildDiscarderProperty>
<strategy class="hudson.tasks.LogRotator">
<daysToKeep>+1</daysToKeep>
<numToKeep>7</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>7</artifactNumToKeep>
</strategy>
</jenkins.model.BuildDiscarderProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<builders>
<hudson.tasks.Shell>
<command>echo &quot;{defined_var|+1}&quot;
echo &quot;{defined_var|-1}&quot;
echo &quot;{undefined_var|+1}&quot;
echo &quot;{undefined_var|-1}&quot;
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

View File

@ -0,0 +1,23 @@
- project:
name: test_variable_default_values
jobs:
- 'variable_default_values':
defined_var: '7'
- job-template:
name: 'variable_default_values'
properties:
- build-discarder:
days-to-keep: '{undefined_var|+1}'
num-to-keep: '{defined_var|+1}'
artifact-days-to-keep: '{undefined_var|-1}'
artifact-num-to-keep: '{defined_var|-1}'
builders:
- shell: |
echo "{{defined_var|+1}}"
echo "{{defined_var|-1}}"
echo "{{undefined_var|+1}}"
echo "{{undefined_var|-1}}"