7

How can I trigger a job in Ansible Tower using its API on a Github branch commit?

I could use a Github webhook but when triggered by a push it occurs regardless of branch. I'm wondering if the webhook payload could provide info but I m not sure how to utilize it within the job. Am I on the right track or is there a better approach?

Thanks.

Carson Cole
  • 4,183
  • 6
  • 25
  • 35

2 Answers2

1

You could use a pipeline using GitHub actions and conditionals. For example:

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

Taken from here.

Rafael de Bem
  • 641
  • 7
  • 15
0

The webhook payload does provide information. Check the extra variables in the output of a job triggered by a webhook. More information about how the payload is exposed as an extra variable can be found here:

https://docs.ansible.com/automation-controller/4.1.0/html/userguide/webhooks.html#payload-output

You can use the values of the payload variables to perform conditional actions with Ansible.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31548337) – β.εηοιτ.βε Apr 16 '22 at 11:17