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
This commit is contained in:
James E. Blair 2017-07-21 10:02:49 -07:00
parent 0ca6461abd
commit 673dbd1441
2 changed files with 20 additions and 16 deletions

View File

@ -229,12 +229,12 @@ additional variables are available:
**zuul.oldrev** **zuul.oldrev**
If the item was enqueued as the result of a change merging or being 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 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** **zuul.newrev**
If the item was enqueued as the result of a change merging or being 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 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 Tag Items
+++++++++ +++++++++
@ -247,14 +247,16 @@ available:
The name of the item's tag (without the `refs/tags/` prefix). The name of the item's tag (without the `refs/tags/` prefix).
**zuul.oldrev** **zuul.oldrev**
If the item was enqueued as the result of a tag being created or If the item was enqueued as the result of a tag being deleted, the
deleted the git sha of the old revision will be included here. previous git sha of the tag will be included here. If the tag was
Otherwise, this value will not be present. created, this will be set to the value
0000000000000000000000000000000000000000.
**zuul.newrev** **zuul.newrev**
If the item was enqueued as the result of a tag being created or If the item was enqueued as the result of a tag being created, the
deleted the git sha of the new revision will be included here. new git sha of the tag will be included here. If the tag was
Otherwise, this value will not be present. deleted, this will be set to the value
0000000000000000000000000000000000000000.
Ref Items Ref Items
+++++++++ +++++++++
@ -265,14 +267,16 @@ to identify the ref. The following additional variables are
available: available:
**zuul.oldrev** **zuul.oldrev**
If the item was enqueued as the result of a ref being created, If the item was enqueued as the result of a ref being deleted, the
deleted, or changed the git sha of the old revision will be included previous git sha of the ref will be included here. If the ref was
here. Otherwise, this value will not be present. created, this will be set to the value
0000000000000000000000000000000000000000.
**zuul.newrev** **zuul.newrev**
If the item was enqueued as the result of a ref being created, If the item was enqueued as the result of a ref being created, the
deleted, or changed the git sha of the new revision will be included new git sha of the ref will be included here. If the ref was
here. Otherwise, this value will not be present. deleted, this will be set to the value
0000000000000000000000000000000000000000.
Working Directory Working Directory
+++++++++++++++++ +++++++++++++++++

View File

@ -171,9 +171,9 @@ class ExecutorClient(object):
zuul_params['change'] = item.change.number zuul_params['change'] = item.change.number
if hasattr(item.change, 'patchset'): if hasattr(item.change, 'patchset'):
zuul_params['patchset'] = 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 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['newrev'] = item.change.newrev
zuul_params['items'] = [] zuul_params['items'] = []
for i in all_items: for i in all_items: