diff --git a/jenkins_jobs/loader.py b/jenkins_jobs/loader.py index 6e9b6b1ce..6ffded141 100644 --- a/jenkins_jobs/loader.py +++ b/jenkins_jobs/loader.py @@ -12,6 +12,7 @@ import io import logging +import warnings from functools import partial from .errors import JenkinsJobsException @@ -71,7 +72,10 @@ class Loader(LocLoader): def load_deprecated_yaml(tag, cls, loader, node): - logger.warning("Tag %r is deprecated, switch to using %r", tag, cls.yaml_tag) + warnings.warn( + f"Tag {tag!r} is deprecated, switch to using {cls.yaml_tag!r}", + UserWarning, + ) return cls.from_yaml(loader, node) diff --git a/tests/loader/fixtures/deprecated-include-raw-escaped001.json b/tests/loader/fixtures/deprecated-include-raw-escaped001.json deleted file mode 100644 index 8ec298fde..000000000 --- a/tests/loader/fixtures/deprecated-include-raw-escaped001.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "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" - } - ], - "description": "", - "name": "test-job-include-raw-1" - } -] diff --git a/tests/loader/fixtures/deprecated-include-raw001.json b/tests/loader/fixtures/deprecated-include-raw001.json deleted file mode 100644 index 8ec298fde..000000000 --- a/tests/loader/fixtures/deprecated-include-raw001.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "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" - } - ], - "description": "", - "name": "test-job-include-raw-1" - } -] diff --git a/tests/loader/fixtures/deprecated-include-raw001.yaml b/tests/loader/fixtures/deprecated-include-raw001.yaml deleted file mode 100644 index 972816c2e..000000000 --- a/tests/loader/fixtures/deprecated-include-raw001.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- job: - name: test-job-include-raw-1 - builders: - - shell: - !include-raw-escape include-raw001-hello-world.sh - - shell: - !include-raw-escape include-raw001-vars.sh diff --git a/tests/loader/fixtures/deprecated-include001.json b/tests/loader/fixtures/deprecated-include001.json deleted file mode 100644 index 1cfc92b55..000000000 --- a/tests/loader/fixtures/deprecated-include001.json +++ /dev/null @@ -1,45 +0,0 @@ -[ - { - "builders": [ - { - "copyartifact": { - "project": "foo", - "filter": "*.tar.gz", - "target": "/home/foo", - "which-build": "last-successful", - "optional": true, - "flatten": true, - "do-not-fingerprint": true, - "parameter-filters": "PUBLISH=true" - } - }, - { - "copyartifact": { - "project": "bar", - "filter": "*.tar.gz", - "target": "/home/foo", - "which-build": "specific-build", - "optional": true, - "flatten": true, - "do-not-fingerprint": 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, - "do-not-fingerprint": true, - "parameter-filters": "PUBLISH=true" - } - } - ], - "description": "", - "name": "test-job-1" - } -] diff --git a/tests/loader/fixtures/deprecated-include001.yaml b/tests/loader/fixtures/deprecated-include001.yaml deleted file mode 100644 index e29a2e9d1..000000000 --- a/tests/loader/fixtures/deprecated-include001.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- job: - name: test-job-1 - builders: - !include include001.yaml.inc diff --git a/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.hello-world.sh b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.hello-world.sh new file mode 100644 index 000000000..800110d8d --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.hello-world.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# Sample script showing how the yaml include-raw-escape tag can be used +# to inline scripts that are maintained outside of the jenkins +# job yaml configuration. + +echo "hello world" + +exit 0 diff --git a/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.vars.sh b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.vars.sh new file mode 100644 index 000000000..eb935564f --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.vars.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# sample script to check that brackets aren't expanded +# when using the include-raw-escape application yaml tag + +VAR1="hello" +VAR2="world" +VAR3="${VAR1} ${VAR2}" + +[[ -n "${VAR3}" ]] && { + # this next section is executed as one + echo "${VAR3}" + exit 0 +} diff --git a/tests/loader/fixtures/deprecated-include-raw-escaped001.xml b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.xml similarity index 85% rename from tests/loader/fixtures/deprecated-include-raw-escaped001.xml rename to tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.xml index 9a48dc3d9..28a36363b 100644 --- a/tests/loader/fixtures/deprecated-include-raw-escaped001.xml +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.xml @@ -13,7 +13,7 @@ #!/bin/bash # -# Sample script showing how the yaml include-raw tag can be used +# Sample script showing how the yaml include-raw-escape tag can be used # to inline scripts that are maintained outside of the jenkins # job yaml configuration. @@ -25,8 +25,8 @@ exit 0 #!/bin/bash # -# sample script to check that brackets aren't escaped -# when using the include-raw application yaml tag +# sample script to check that brackets aren't expanded +# when using the include-raw-escape application yaml tag VAR1="hello" VAR2="world" diff --git a/tests/loader/fixtures/deprecated-include-raw-escaped001.yaml b/tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.yaml similarity index 56% rename from tests/loader/fixtures/deprecated-include-raw-escaped001.yaml rename to tests/yamlparser/job_fixtures/deprecated-include-raw-escaped001.yaml index 2853d03ba..96c23c034 100644 --- a/tests/loader/fixtures/deprecated-include-raw-escaped001.yaml +++ b/tests/yamlparser/job_fixtures/deprecated-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 deprecated-include-raw-escaped001.hello-world.sh - shell: - !include-raw-escape include-raw001-vars.sh + !include-raw-escape deprecated-include-raw-escaped001.vars.sh - project: name: test-job-template-1 diff --git a/tests/yamlparser/job_fixtures/deprecated-include-raw001.hello-world.sh b/tests/yamlparser/job_fixtures/deprecated-include-raw001.hello-world.sh new file mode 100644 index 000000000..74ba06c13 --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw001.hello-world.sh @@ -0,0 +1,9 @@ +#!/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 diff --git a/tests/yamlparser/job_fixtures/deprecated-include-raw001.vars.sh b/tests/yamlparser/job_fixtures/deprecated-include-raw001.vars.sh new file mode 100644 index 000000000..17518b6dd --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw001.vars.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# sample script to check that brackets are expanded +# when using the include-raw application yaml tag + +VAR1="hello" +VAR2="world" +VAR3="${{VAR1}} ${{VAR2}}" + +[[ -n "${{VAR3}}" ]] && {{ + # this next section is executed as one + echo "${{VAR3}}" + exit 0 +}} diff --git a/tests/yamlparser/job_fixtures/deprecated-include-raw001.xml b/tests/yamlparser/job_fixtures/deprecated-include-raw001.xml new file mode 100644 index 000000000..3d46a8a43 --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw001.xml @@ -0,0 +1,45 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + #!/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 + + + + #!/bin/bash +# +# sample script to check that brackets are expanded +# when using the include-raw application yaml tag + +VAR1="hello" +VAR2="world" +VAR3="${VAR1} ${VAR2}" + +[[ -n "${VAR3}" ]] && { + # this next section is executed as one + echo "${VAR3}" + exit 0 +} + + + + + + diff --git a/tests/yamlparser/job_fixtures/deprecated-include-raw001.yaml b/tests/yamlparser/job_fixtures/deprecated-include-raw001.yaml new file mode 100644 index 000000000..ac0545f8d --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include-raw001.yaml @@ -0,0 +1,7 @@ +- job: + name: test-job-include-raw-1 + builders: + - shell: + !include-raw deprecated-include-raw001.hello-world.sh + - shell: + !include-raw deprecated-include-raw001.vars.sh diff --git a/tests/yamlparser/job_fixtures/deprecated-include001.xml b/tests/yamlparser/job_fixtures/deprecated-include001.xml index 2274117ee..b8ec1a012 100644 --- a/tests/yamlparser/job_fixtures/deprecated-include001.xml +++ b/tests/yamlparser/job_fixtures/deprecated-include001.xml @@ -9,16 +9,50 @@ true - + + + foo + *.tar.gz + /home/foo + true + true + true + PUBLISH=true + + + + false + + + + bar + *.tar.gz + /home/foo + true + true + true + PUBLISH=true + + + + 123 + + + + baz + *.tar.gz + /home/foo + true + true + true + PUBLISH=true + + + + false + + + - - - 3 - true - false - 150 - 90 - elastic - - + diff --git a/tests/yamlparser/job_fixtures/deprecated-include001.yaml b/tests/yamlparser/job_fixtures/deprecated-include001.yaml new file mode 100644 index 000000000..a73bf07e5 --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include001.yaml @@ -0,0 +1,4 @@ +- job: + name: test-job-1 + builders: + !include deprecated-include001.yaml.inc diff --git a/tests/yamlparser/job_fixtures/deprecated-include001.yaml.inc b/tests/yamlparser/job_fixtures/deprecated-include001.yaml.inc new file mode 100644 index 000000000..c0ed1c0ff --- /dev/null +++ b/tests/yamlparser/job_fixtures/deprecated-include001.yaml.inc @@ -0,0 +1,18 @@ +- copyartifact: ©tarball + project: foo + filter: "*.tar.gz" + target: /home/foo + which-build: last-successful + optional: true + flatten: true + do-not-fingerprint: true + parameter-filters: PUBLISH=true +- copyartifact: + <<: *copytarball + project: bar + which-build: specific-build + build-number: 123 +- copyartifact: + <<: *copytarball + project: baz + which-build: upstream-build diff --git a/tests/yamlparser/test_jobs.py b/tests/yamlparser/test_jobs.py index b8a4ff805..7f4e6d2df 100644 --- a/tests/yamlparser/test_jobs.py +++ b/tests/yamlparser/test_jobs.py @@ -35,7 +35,12 @@ def scenario(request): return request.param -def test_yaml_snippet(check_job): +def test_yaml_snippet(scenario, check_job): # Some tests using config with 'include_path' expect JJB root to be current directory. os.chdir(Path(__file__).parent / "../..") - check_job() + if scenario.name.startswith("deprecated-"): + with pytest.warns(UserWarning) as record: + check_job() + assert "is deprecated" in str(record[0].message) + else: + check_job()