From 673dbd144146ecafa423061e769686c6282c8555 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 21 Jul 2017 10:02:49 -0700 Subject: [PATCH] Undefine Zuul variables in Ansible when appropriate When variables such as branch, tag, oldrev, and newrev are not applicable, ensure that they are not defined at all as Ansible variables. Update the documentation to be more clear on oldrev and newrev. Change-Id: I56d9a6496467de2f328eb9a43cc52c5f7ef73310 --- doc/source/user/jobs.rst | 32 ++++++++++++++++++-------------- zuul/executor/client.py | 4 ++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/doc/source/user/jobs.rst b/doc/source/user/jobs.rst index aad43d71f2..a367aa0fe8 100644 --- a/doc/source/user/jobs.rst +++ b/doc/source/user/jobs.rst @@ -229,12 +229,12 @@ additional variables are available: **zuul.oldrev** If the item was enqueued as the result of a change merging or being pushed to the branch, the git sha of the old revision will be - included here. Otherwise, this value will not be present. + included here. Otherwise, this variable will be undefined. **zuul.newrev** If the item was enqueued as the result of a change merging or being pushed to the branch, the git sha of the new revision will be - included here. Otherwise, this value will not be present. + included here. Otherwise, this variable will be undefined. Tag Items +++++++++ @@ -247,14 +247,16 @@ available: The name of the item's tag (without the `refs/tags/` prefix). **zuul.oldrev** - If the item was enqueued as the result of a tag being created or - deleted the git sha of the old revision will be included here. - Otherwise, this value will not be present. + If the item was enqueued as the result of a tag being deleted, the + previous git sha of the tag will be included here. If the tag was + created, this will be set to the value + 0000000000000000000000000000000000000000. **zuul.newrev** - If the item was enqueued as the result of a tag being created or - deleted the git sha of the new revision will be included here. - Otherwise, this value will not be present. + If the item was enqueued as the result of a tag being created, the + new git sha of the tag will be included here. If the tag was + deleted, this will be set to the value + 0000000000000000000000000000000000000000. Ref Items +++++++++ @@ -265,14 +267,16 @@ to identify the ref. The following additional variables are available: **zuul.oldrev** - If the item was enqueued as the result of a ref being created, - deleted, or changed the git sha of the old revision will be included - here. Otherwise, this value will not be present. + If the item was enqueued as the result of a ref being deleted, the + previous git sha of the ref will be included here. If the ref was + created, this will be set to the value + 0000000000000000000000000000000000000000. **zuul.newrev** - If the item was enqueued as the result of a ref being created, - deleted, or changed the git sha of the new revision will be included - here. Otherwise, this value will not be present. + If the item was enqueued as the result of a ref being created, the + new git sha of the ref will be included here. If the ref was + deleted, this will be set to the value + 0000000000000000000000000000000000000000. Working Directory +++++++++++++++++ diff --git a/zuul/executor/client.py b/zuul/executor/client.py index 52cc403b38..beb8964fa8 100644 --- a/zuul/executor/client.py +++ b/zuul/executor/client.py @@ -171,9 +171,9 @@ class ExecutorClient(object): zuul_params['change'] = item.change.number if hasattr(item.change, 'patchset'): zuul_params['patchset'] = item.change.patchset - if hasattr(item.change, 'oldrev'): + if hasattr(item.change, 'oldrev') and item.change.oldrev: zuul_params['oldrev'] = item.change.oldrev - if hasattr(item.change, 'newrev'): + if hasattr(item.change, 'newrev') and item.change.newrev: zuul_params['newrev'] = item.change.newrev zuul_params['items'] = [] for i in all_items: