2

Environment:

BitBucket
Concourse 3.14.0

Wondering is it possible to configure Concourse pipeline with Git webhook which will check if new commit has happened and it would trigger a pipeline build based on that trigger? I looked at https://concourse-ci.org/resources.html#resource-webhook-token, but it does not tell me how to get a webhook token from Concourse and if it does support what I am asking.
Any feedback is very much appreciated.

user2362699
  • 586
  • 6
  • 22
  • I recently came across this page while trying to set things up. It looks like the webhook token can be any arbitrary string, and the only req is that it matches the token added to GitHub/BitBucket and Concourse in the pipeline config. If anyone has a documentation link validating/invalidating that statement, I'd love see it. – Jacob Holloway Oct 26 '18 at 12:01

2 Answers2

5

Concourse resources usually pull any new versions every minute or so. Whenever this frequency doesn't suit your needs, you can modify it with the check_every resource property. But values lower that 1m (one minute) are typically considered aggressive. Github implements quotas for API calls and when you have many pipelines, you don't want them to fail because you've hit some quota limits.

In case you want Concourse to immediately react on published new versions for the pipeline resources, you need to reverse the pattern. Instead of Concourse pulling any new versions at some defined frequency, you start pushing the information to Concourse that some new versions are to be pulled. This reversed “push” pattern involves triggering “resource checks” whenever new versions are created on the resource.

Trigger immediate resource checks

Every Concourse resource can enable a resource-check triggering URL with the webhook_token resource property. This URL includes the webhook_token secret in its query string, and is supposed to receive a mere POST HTTP request.

With Github repositories, you can POST to this URL with a Github workflow, relying on a standard Github action from the marketplace (recommended, first choice), or a Github webhook (second choice).

Using a Github workflow

You need to commit and push a YAML file in the .github/workflows folder of your Github repository, in order to define your workflow. Refer to the documentation of the “Trigger Concourse resource-check” action for detailed examples. It's very easy, as only five simple inputs need to be configured.

Using a Github webhook

With this alternative, you can manually setup a Github webhook in your repository. The URL depends on the resource for which an immediate check is to be triggered, so you can't set it up at your Github organization level. The webhook_token secret in appended in clear-text to the URL set up for the webhook, and can't be stored as a Github secret. Github webhook don't support fetching any Github secret.

And in case you're bored of manually set up webhooks, automated setup is possible with the github-webhook resource. You can even trigger the webhook recreation whenever the webhook_token secret changes in Credhub, with the help of the Credhub resource. I've done some working code implementing this idea, see those example jobs and those example resource definitions.

But I definitely recommend using a Github workflow with the “Trigger Concourse resource-check” action as a first choice.

3

I think you are looking for this resource - https://github.com/concourse/git-resource

It automatically checks for any new commit in your git repository and you can run other jobs based on that.

Example pipeline.yml:

resources:
- name: git-repo
  type: git
  source:
    uri: git@github.com:concourse/git-resource.git
    branch: master
    private_key: {{GIT_KEY}}

jobs: 
- name: run-on-new-commit
- get: git-repo
  trigger: true
- task: do-something-else
Karanbir
  • 84
  • 4
  • Thank you so much @Karanbir. I was wondering, if you can tell me if I can change the interval of checking the repo? I think it is 1m currently, correct ? – user2362699 Jul 12 '18 at 16:55
  • I don't think default is 1m. It just picks it up whenever there is new commit, delay of 5 - 10 seconds. If you want to change interval either you can modify the concourse resource or you can attach a time resource. – Karanbir Jul 12 '18 at 17:20
  • Thanks so much for your feedback Karanbir!! – user2362699 Jul 12 '18 at 18:04