Page MenuHomePhabricator

Allow ref-updated listener to filter out tag deletions
Closed, ResolvedPublic

Description

We currently listen to this event like this:

- name: publish
  description: Whenever tags are published.
  manager: IndependentPipelineManager
  trigger:
    gerrit:
     - event: ref-updated
       ref: ^refs/tags/.*$

The ref-updated listener for Zuul pipelines can be triggered in one of three ways.

  • tag create
    • ZUUL_OLDREV=00000000000000000000000000000000
    • ZUUL_NEWREV=123456789abcdef123456789abcdef12
  • tag delete
    • ZUUL_OLDREV=123456789abcdef123456789abcdef12
    • ZUUL_NEWREV=00000000000000000000000000000000
  • tag alter:
    • ZUUL_OLDREV=123456789abcdef123456789abcdef12
    • ZUUL_NEWREV=abcdef123456789abcdef123456789ab

Instead of having to assert the value of these environment variables inside every job, this should be handled at the Zuul level by providing a way to filter these events more precisely.

Perhaps in the trigger.gerrit match object we can expose a action property with values create, delete and alter. Then the Zuul layout can match against that with a string or regex.

We could also expose the oldrev/newrev but that doesn't seem very useful as the sha1 is meaningless except for the 000 value.

See also:

Event Timeline

Krinkle raised the priority of this task from to High.
Krinkle updated the task description. (Show Details)
Krinkle added subscribers: Krinkle, hashar.

We only have 1 job that does this currently (train.yaml) and it seems easy enough to copy around to the few jobs that need it. It's also documented upstream now.

hashar added a subscriber: thcipriani.

Cool we have a task for this! I am reopening it since @thcipriani looked into this recently for https://gerrit.wikimedia.org/r/#/c/integration/config/+/494778/

That is to be used for our post pipeline currently defined as:

zuul/layout.yaml
# Pipeline reacting whenever a reference is updated
- name: post
  description: Jobs for when a branch is created or updated.
  manager: IndependentPipelineManager
  source: gerrit
  trigger:
    gerrit:
     - event: ref-updated
       # If it starts with refs/, then it's a tag or a special branch.
       # Without that prefix, it's a "normal" branch.
       # https://zuul-ci.org/docs/zuul/admin/drivers/gerrit.html#trigger-configuration
       ref: ^(?!(devnull|refs/.*)).*$

On the change I wrote:


TLDR: use:

- event: ref-updated
   ref: ^refs/heads/.*$
   ignore-deletes: True

Bonus if we write a test :)

That is from 2013, and apparently we never used a post pipeline (based on: git log --follow -Gpost: zuul/layout.yaml).

I borrowed that either from Zuul documentation or from OpenStack config files. One sure thing, Zuul code as test layout that uses the inverted logic:

fixtures/layout-ref.yaml
- name: post
  manager: IndependentPipelineManager
  trigger:
  review_gerrit:
    - event: ref-updated
      ref: ^(?!refs/).*$
      ignore-deletes: True

The logic is inverted explicitly to drop all events of the kind:

  • refs/changes/45/12345/meta
  • refs/changes/45/12345/1
  • refs/notes/review

See P8167 for an example of events emitted when a change is pushed. The first one has:

  • refName: refs/heads/master

The Zuul version we have -and its doc- use the negative regex because it matches the behavior of some old gerrit. For branches updates it used to report:

  • refName: master

And on deletion:

  • refName: devnull

Thus our regex is there to dismiss patchsets / notes etc as well as skip references deletions.

In Zuul fixtures I even found the following text:

Add option to ignore ref-updated events emitted by branch deletions

https://review.openstack.org/178833

Which is I guess refers to the implementation of ignore-deletes.


Change 494778 had a related patch set uploaded (by Hashar; owner: Thcipriani):
[integration/config@master] post pipeline: fix ref filter

https://gerrit.wikimedia.org/r/494778

Change 494778 merged by jenkins-bot:
[integration/config@master] post pipeline: fix ref filter

https://gerrit.wikimedia.org/r/494778

Fixed upstream which ignores reference deletions by default. Further tweaked by @thcipriani to update the reference filter to match current Zuul version.

See T96390#5077086 above for the long explanation :)