diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 56485ebd6..3f75ad477 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -1117,7 +1117,10 @@ def github_pull_request(registry, xml_parent, data): error_comment ) - cancel_builds_on_update = data.get('cancel-builds-on-update', False) + # When the value of cancel-builds-on-update comes from deep_formatter, + # the value is of type 'str', otherwise the value is of type 'bool' + cancel_builds_on_update = str( + data.get('cancel-builds-on-update', False)).lower() == 'true' # We want to have only one 'extensions' subelement, even if status # handling, comment handling and other extensions are enabled. diff --git a/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable001.xml b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable001.xml new file mode 100644 index 000000000..0832d9602 --- /dev/null +++ b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable001.xml @@ -0,0 +1,38 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + + + + + + + + + false + + + + false + false + false + false + + + + + + + + + diff --git a/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable001.yaml b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable001.yaml new file mode 100644 index 000000000..a3245c2c2 --- /dev/null +++ b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable001.yaml @@ -0,0 +1,12 @@ +--- +- job-template: + name: 'github-pull-request-variable-test-true' + triggers: + - github-pull-request: + cancel-builds-on-update: '{test-var}' + +- project: + name: test-true + test-var: true + jobs: + - 'github-pull-request-variable-test-true' diff --git a/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable002.xml b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable002.xml new file mode 100644 index 000000000..1d9133094 --- /dev/null +++ b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable002.xml @@ -0,0 +1,35 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + + + + + + + + + false + + + + false + false + false + false + + + + + + diff --git a/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable002.yaml b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable002.yaml new file mode 100644 index 000000000..39c35c423 --- /dev/null +++ b/tests/yamlparser/fixtures/github_cancel_builds_on_update_variable002.yaml @@ -0,0 +1,12 @@ +--- +- job-template: + name: 'github-pull-request-variable-test-false' + triggers: + - github-pull-request: + cancel-builds-on-update: '{test-var}' + +- project: + name: test-false + test-var: false + jobs: + - 'github-pull-request-variable-test-false'