diff options
author | Darragh Bailey <daragh.bailey@gmail.com> | 2015-05-06 01:09:45 +0100 |
---|---|---|
committer | Darragh Bailey <daragh.bailey@gmail.com> | 2015-09-18 00:37:00 +0100 |
commit | 3d728c71a850db3515c1e7f8c5816a595007ba17 (patch) | |
tree | 22c40ec47f8b55b098196a58fa215197572c4800 /tests | |
parent | 59a8342f8502f82e0fdfa66068779875f8d12319 (diff) | |
download | python-jenkins-job-builder-3d728c71a850db3515c1e7f8c5816a595007ba17.tar.gz python-jenkins-job-builder-3d728c71a850db3515c1e7f8c5816a595007ba17.tar.xz python-jenkins-job-builder-3d728c71a850db3515c1e7f8c5816a595007ba17.zip |
Separate out custom yaml tags into separate classes
Implement custom tags for including files by subclassing YAMLObject to
allow PyYAML to easily convert from the Yaml nodes.
Change to support both lists and strings under the same tag name and
deprecate the old tag naming. Rename tests using the deprecated tags to
ensure they are not used for examples. Remove old tests that simply
duplicate others.
Change-Id: I1a8d3376ea6e4918a2adb05fb856b939a3124d74
Diffstat (limited to 'tests')
22 files changed, 198 insertions, 160 deletions
diff --git a/tests/localyaml/fixtures/deprecated-include-raw-escaped001.json b/tests/localyaml/fixtures/deprecated-include-raw-escaped001.json new file mode 100644 index 00000000..268b0aab --- /dev/null +++ b/tests/localyaml/fixtures/deprecated-include-raw-escaped001.json @@ -0,0 +1,24 @@ +[ + { + "job-template": { + "name": "test-job-include-raw-{num}", + "builders": [ + { + "shell": "#!/bin/bash\n#\n# Sample script showing how the yaml include-raw tag can be used\n# to inline scripts that are maintained outside of the jenkins\n# job yaml configuration.\n\necho \"hello world\"\n\nexit 0\n" + }, + { + "shell": "#!/bin/bash\n#\n# sample script to check that brackets aren't escaped\n# when using the include-raw application yaml tag\n\nVAR1=\"hello\"\nVAR2=\"world\"\nVAR3=\"${{VAR1}} ${{VAR2}}\"\n\n[[ -n \"${{VAR3}}\" ]] && {{\n # this next section is executed as one\n echo \"${{VAR3}}\"\n exit 0\n}}\n\n" + } + ] + } + }, + { + "project": { + "name": "test-job-template-1", + "num": 1, + "jobs": [ + "test-job-include-raw-{num}" + ] + } + } +] diff --git a/tests/localyaml/fixtures/deprecated-include-raw-escaped001.yaml b/tests/localyaml/fixtures/deprecated-include-raw-escaped001.yaml new file mode 100644 index 00000000..2853d03b --- /dev/null +++ b/tests/localyaml/fixtures/deprecated-include-raw-escaped001.yaml @@ -0,0 +1,13 @@ +- job-template: + name: test-job-include-raw-{num} + builders: + - shell: + !include-raw-escape include-raw001-hello-world.sh + - shell: + !include-raw-escape include-raw001-vars.sh + +- project: + name: test-job-template-1 + num: 1 + jobs: + - 'test-job-include-raw-{num}' diff --git a/tests/localyaml/fixtures/deprecated-include-raw001.json b/tests/localyaml/fixtures/deprecated-include-raw001.json new file mode 100644 index 00000000..e9540524 --- /dev/null +++ b/tests/localyaml/fixtures/deprecated-include-raw001.json @@ -0,0 +1,15 @@ +[ + { + "job": { + "name": "test-job-include-raw-1", + "builders": [ + { + "shell": "#!/bin/bash\n#\n# Sample script showing how the yaml include-raw tag can be used\n# to inline scripts that are maintained outside of the jenkins\n# job yaml configuration.\n\necho \"hello world\"\n\nexit 0\n" + }, + { + "shell": "#!/bin/bash\n#\n# sample script to check that brackets aren't escaped\n# when using the include-raw application yaml tag\n\nVAR1=\"hello\"\nVAR2=\"world\"\nVAR3=\"${VAR1} ${VAR2}\"\n\n[[ -n \"${VAR3}\" ]] && {\n # this next section is executed as one\n echo \"${VAR3}\"\n exit 0\n}\n\n" + } + ] + } + } +] diff --git a/tests/localyaml/fixtures/deprecated-include-raw001.yaml b/tests/localyaml/fixtures/deprecated-include-raw001.yaml new file mode 100644 index 00000000..ba2f8ef0 --- /dev/null +++ b/tests/localyaml/fixtures/deprecated-include-raw001.yaml @@ -0,0 +1,7 @@ +- job: + name: test-job-include-raw-1 + builders: + - shell: + !include-raw include-raw001-hello-world.sh + - shell: + !include-raw include-raw001-vars.sh diff --git a/tests/localyaml/fixtures/deprecated-include001.json b/tests/localyaml/fixtures/deprecated-include001.json new file mode 100644 index 00000000..3b29d240 --- /dev/null +++ b/tests/localyaml/fixtures/deprecated-include001.json @@ -0,0 +1,43 @@ +[ + { + "job": { + "name": "test-job-1", + "builders": [ + { + "copyartifact": { + "project": "foo", + "filter": "*.tar.gz", + "target": "/home/foo", + "which-build": "last-successful", + "optional": true, + "flatten": true, + "parameter-filters": "PUBLISH=true" + } + }, + { + "copyartifact": { + "project": "bar", + "filter": "*.tar.gz", + "target": "/home/foo", + "which-build": "specific-build", + "optional": true, + "flatten": true, + "parameter-filters": "PUBLISH=true", + "build-number": 123 + } + }, + { + "copyartifact": { + "project": "baz", + "filter": "*.tar.gz", + "target": "/home/foo", + "which-build": "upstream-build", + "optional": true, + "flatten": true, + "parameter-filters": "PUBLISH=true" + } + } + ] + } + } +] diff --git a/tests/localyaml/fixtures/deprecated-include001.yaml b/tests/localyaml/fixtures/deprecated-include001.yaml new file mode 100644 index 00000000..e29a2e9d --- /dev/null +++ b/tests/localyaml/fixtures/deprecated-include001.yaml @@ -0,0 +1,4 @@ +- job: + name: test-job-1 + builders: + !include include001.yaml.inc diff --git a/tests/localyaml/fixtures/exception_include001.yaml b/tests/localyaml/fixtures/exception_include001.yaml index 828b541b..66d9f76e 100644 --- a/tests/localyaml/fixtures/exception_include001.yaml +++ b/tests/localyaml/fixtures/exception_include001.yaml @@ -12,4 +12,4 @@ - job: name: test-job-1 builders: - !include exception_include001.yaml.inc + !include: exception_include001.yaml.inc diff --git a/tests/localyaml/fixtures/include-raw-escaped001.yaml b/tests/localyaml/fixtures/include-raw-escaped001.yaml index 2853d03b..df466828 100644 --- a/tests/localyaml/fixtures/include-raw-escaped001.yaml +++ b/tests/localyaml/fixtures/include-raw-escaped001.yaml @@ -2,9 +2,9 @@ name: test-job-include-raw-{num} builders: - shell: - !include-raw-escape include-raw001-hello-world.sh + !include-raw-escape: include-raw001-hello-world.sh - shell: - !include-raw-escape include-raw001-vars.sh + !include-raw-escape: include-raw001-vars.sh - project: name: test-job-template-1 diff --git a/tests/localyaml/fixtures/include-raw001.yaml b/tests/localyaml/fixtures/include-raw001.yaml index ba2f8ef0..dfa5fb71 100644 --- a/tests/localyaml/fixtures/include-raw001.yaml +++ b/tests/localyaml/fixtures/include-raw001.yaml @@ -2,6 +2,6 @@ name: test-job-include-raw-1 builders: - shell: - !include-raw include-raw001-hello-world.sh + !include-raw: include-raw001-hello-world.sh - shell: - !include-raw include-raw001-vars.sh + !include-raw: include-raw001-vars.sh diff --git a/tests/localyaml/fixtures/include001.yaml b/tests/localyaml/fixtures/include001.yaml index e29a2e9d..ed662f8d 100644 --- a/tests/localyaml/fixtures/include001.yaml +++ b/tests/localyaml/fixtures/include001.yaml @@ -1,4 +1,4 @@ - job: name: test-job-1 builders: - !include include001.yaml.inc + !include: include001.yaml.inc diff --git a/tests/yamlparser/fixtures/include002.xml b/tests/yamlparser/fixtures/deprecated-include001.xml index 2274117e..2274117e 100644 --- a/tests/yamlparser/fixtures/include002.xml +++ b/tests/yamlparser/fixtures/deprecated-include001.xml diff --git a/tests/yamlparser/fixtures/include-raw-escape001.yaml b/tests/yamlparser/fixtures/include-raw-escape001.yaml index abb5b93b..d41417e4 100644 --- a/tests/yamlparser/fixtures/include-raw-escape001.yaml +++ b/tests/yamlparser/fixtures/include-raw-escape001.yaml @@ -11,7 +11,7 @@ keep-system-variables: true builders: - shell: - !include-raw-escape include-raw-escape001-echo-vars.sh + !include-raw-escape: include-raw-escape001-echo-vars.sh - project: diff --git a/tests/yamlparser/fixtures/include-raw001.xml b/tests/yamlparser/fixtures/include-raw001.xml index 688a0bb9..494410c5 100644 --- a/tests/yamlparser/fixtures/include-raw001.xml +++ b/tests/yamlparser/fixtures/include-raw001.xml @@ -19,20 +19,48 @@ </EnvInjectJobProperty> </properties> <scm class="hudson.scm.NullSCM"/> - <builders> - <hudson.tasks.Shell> - <command>#!/bin/bash -# -# Sample script showing how the yaml include-raw tag can be used -# to inline scripts that are maintained outside of the jenkins -# job yaml configuration. - -echo "hello world" - -exit 0 -</command> - </hudson.tasks.Shell> - </builders> + <builders/> <publishers/> - <buildWrappers/> + <buildWrappers> + <hudson.plugins.build__timeout.BuildTimeoutWrapper> + <timeoutMinutes>3</timeoutMinutes> + <failBuild>true</failBuild> + <writingDescription>false</writingDescription> + <timeoutPercentage>150</timeoutPercentage> + <timeoutMinutesElasticDefault>90</timeoutMinutesElasticDefault> + <timeoutType>elastic</timeoutType> + </hudson.plugins.build__timeout.BuildTimeoutWrapper> + <org.jenkinsci.plugins.preSCMbuildstep.PreSCMBuildStepsWrapper> + <buildSteps> + <hudson.tasks.Shell> + <command>#!/bin/bash +echo "Doing somethiung cool" +</command> + </hudson.tasks.Shell> + <hudson.tasks.Shell> + <command>#!/bin/zsh +echo "Doing somethin cool with zsh" +</command> + </hudson.tasks.Shell> + <hudson.tasks.Ant> + <targets>target1 target2</targets> + <antName>Standard Ant</antName> + </hudson.tasks.Ant> + <EnvInjectBuilder> + <info> + <propertiesFilePath>example.prop</propertiesFilePath> + <propertiesContent>EXAMPLE=foo-bar</propertiesContent> + </info> + </EnvInjectBuilder> + </buildSteps> + </org.jenkinsci.plugins.preSCMbuildstep.PreSCMBuildStepsWrapper> + <com.michelin.cio.hudson.plugins.copytoslave.CopyToSlaveBuildWrapper> + <includes>file1,file2*.txt</includes> + <excludes>file2bad.txt</excludes> + <flatten>false</flatten> + <includeAntExcludes>false</includeAntExcludes> + <relativeTo>userContent</relativeTo> + <hudsonHomeRelative>false</hudsonHomeRelative> + </com.michelin.cio.hudson.plugins.copytoslave.CopyToSlaveBuildWrapper> + </buildWrappers> </project> diff --git a/tests/yamlparser/fixtures/include-raw001.yaml b/tests/yamlparser/fixtures/include-raw001.yaml index a89f61ea..bff63ccd 100644 --- a/tests/yamlparser/fixtures/include-raw001.yaml +++ b/tests/yamlparser/fixtures/include-raw001.yaml @@ -1,10 +1,45 @@ +# vim: sw=4 ts=4 et +- wrapper: + name: timeout-wrapper + wrappers: + - timeout: + fail: true + elastic-percentage: 150 + elastic-default-timeout: 90 + type: elastic + +- wrapper: + name: pre-scm-shell-ant + wrappers: + - pre-scm-buildstep: + - shell: + !include-raw: include-raw002-cool.sh + - shell: + !include-raw: include-raw002-cool.zsh + - ant: + targets: "target1 target2" + ant-name: "Standard Ant" + - inject: + properties-file: example.prop + properties-content: EXAMPLE=foo-bar + +- wrapper: + name: copy-files + wrappers: + - copy-to-slave: + includes: + - file1 + - file2*.txt + excludes: + - file2bad.txt + + - job: - name: test-job-2 + name: test-job-3 + wrappers: + !include: include001.yaml.inc properties: - inject: keep-build-variables: true keep-system-variables: true - builders: - - shell: - !include-raw ../../localyaml/fixtures/include-raw001-hello-world.sh diff --git a/tests/yamlparser/fixtures/include-raw002.xml b/tests/yamlparser/fixtures/include-raw002.xml deleted file mode 100644 index 494410c5..00000000 --- a/tests/yamlparser/fixtures/include-raw002.xml +++ /dev/null @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<project> - <actions/> - <description><!-- Managed by Jenkins Job Builder --></description> - <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties> - <EnvInjectJobProperty> - <info> - <loadFilesFromMaster>false</loadFilesFromMaster> - </info> - <on>true</on> - <keepJenkinsSystemVariables>true</keepJenkinsSystemVariables> - <keepBuildVariables>true</keepBuildVariables> - <overrideBuildParameters>false</overrideBuildParameters> - </EnvInjectJobProperty> - </properties> - <scm class="hudson.scm.NullSCM"/> - <builders/> - <publishers/> - <buildWrappers> - <hudson.plugins.build__timeout.BuildTimeoutWrapper> - <timeoutMinutes>3</timeoutMinutes> - <failBuild>true</failBuild> - <writingDescription>false</writingDescription> - <timeoutPercentage>150</timeoutPercentage> - <timeoutMinutesElasticDefault>90</timeoutMinutesElasticDefault> - <timeoutType>elastic</timeoutType> - </hudson.plugins.build__timeout.BuildTimeoutWrapper> - <org.jenkinsci.plugins.preSCMbuildstep.PreSCMBuildStepsWrapper> - <buildSteps> - <hudson.tasks.Shell> - <command>#!/bin/bash -echo "Doing somethiung cool" -</command> - </hudson.tasks.Shell> - <hudson.tasks.Shell> - <command>#!/bin/zsh -echo "Doing somethin cool with zsh" -</command> - </hudson.tasks.Shell> - <hudson.tasks.Ant> - <targets>target1 target2</targets> - <antName>Standard Ant</antName> - </hudson.tasks.Ant> - <EnvInjectBuilder> - <info> - <propertiesFilePath>example.prop</propertiesFilePath> - <propertiesContent>EXAMPLE=foo-bar</propertiesContent> - </info> - </EnvInjectBuilder> - </buildSteps> - </org.jenkinsci.plugins.preSCMbuildstep.PreSCMBuildStepsWrapper> - <com.michelin.cio.hudson.plugins.copytoslave.CopyToSlaveBuildWrapper> - <includes>file1,file2*.txt</includes> - <excludes>file2bad.txt</excludes> - <flatten>false</flatten> - <includeAntExcludes>false</includeAntExcludes> - <relativeTo>userContent</relativeTo> - <hudsonHomeRelative>false</hudsonHomeRelative> - </com.michelin.cio.hudson.plugins.copytoslave.CopyToSlaveBuildWrapper> - </buildWrappers> -</project> diff --git a/tests/yamlparser/fixtures/include-raw002.yaml b/tests/yamlparser/fixtures/include-raw002.yaml deleted file mode 100644 index cd0f2604..00000000 --- a/tests/yamlparser/fixtures/include-raw002.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# vim: sw=4 ts=4 et -- wrapper: - name: timeout-wrapper - wrappers: - - timeout: - fail: true - elastic-percentage: 150 - elastic-default-timeout: 90 - type: elastic - -- wrapper: - name: pre-scm-shell-ant - wrappers: - - pre-scm-buildstep: - - shell: - !include-raw include-raw002-cool.sh - - shell: - !include-raw include-raw002-cool.zsh - - ant: - targets: "target1 target2" - ant-name: "Standard Ant" - - inject: - properties-file: example.prop - properties-content: EXAMPLE=foo-bar - -- wrapper: - name: copy-files - wrappers: - - copy-to-slave: - includes: - - file1 - - file2*.txt - excludes: - - file2bad.txt - - -- job: - name: test-job-3 - wrappers: - !include include001.yaml.inc - properties: - - inject: - keep-build-variables: true - keep-system-variables: true - diff --git a/tests/yamlparser/fixtures/include-rawunicode001.yaml b/tests/yamlparser/fixtures/include-rawunicode001.yaml index e9c30366..e1379dc6 100644 --- a/tests/yamlparser/fixtures/include-rawunicode001.yaml +++ b/tests/yamlparser/fixtures/include-rawunicode001.yaml @@ -3,7 +3,7 @@ wrappers: - pre-scm-buildstep: - shell: - !include-raw include-rawunicode001-cool.sh + !include-raw: include-rawunicode001-cool.sh - job: name: test-unicode-raw-include-wrapper diff --git a/tests/yamlparser/fixtures/include001.yaml b/tests/yamlparser/fixtures/include001.yaml index 85a54525..8c7c3cb0 100644 --- a/tests/yamlparser/fixtures/include001.yaml +++ b/tests/yamlparser/fixtures/include001.yaml @@ -38,7 +38,7 @@ - job: name: test-job-1 wrappers: - !include include001.yaml.inc + !include: include001.yaml.inc properties: - inject: keep-build-variables: true diff --git a/tests/yamlparser/fixtures/include002.yaml b/tests/yamlparser/fixtures/include002.yaml deleted file mode 100644 index 13a2f121..00000000 --- a/tests/yamlparser/fixtures/include002.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# vim: sw=4 ts=4 et -- default: - name: default-timeout-wrapper - timeout: &timeout - fail: true - elastic-percentage: 150 - elastic-default-timeout: 90 - type: elastic - -# include that uses timeout alias -- wrapper: !include include002_1.yaml.inc - -- job: - name: test-job-1 - wrappers: - !include include002.yaml.inc diff --git a/tests/yamlparser/fixtures/include002.yaml.inc b/tests/yamlparser/fixtures/include002.yaml.inc deleted file mode 100644 index e41c6be6..00000000 --- a/tests/yamlparser/fixtures/include002.yaml.inc +++ /dev/null @@ -1 +0,0 @@ -- timeout-wrapper diff --git a/tests/yamlparser/fixtures/include002_1.yaml.inc b/tests/yamlparser/fixtures/include002_1.yaml.inc deleted file mode 100644 index b127f07b..00000000 --- a/tests/yamlparser/fixtures/include002_1.yaml.inc +++ /dev/null @@ -1,3 +0,0 @@ -name: timeout-wrapper -wrappers: - - timeout: *timeout diff --git a/tests/yamlparser/fixtures/include_path002.yaml b/tests/yamlparser/fixtures/include_path002.yaml index 70b3f186..0d273b8b 100644 --- a/tests/yamlparser/fixtures/include_path002.yaml +++ b/tests/yamlparser/fixtures/include_path002.yaml @@ -5,4 +5,4 @@ - job-template: name: 'include_path' - description: !include test.inc
\ No newline at end of file + description: !include: test.inc |