Once off configuration builds in concourse

258 Views Asked by At

I am trying to trigger once off build for setting configurations for a GitHub Repo. Like configuring webhooks to a GitHub repo. Right now we have a job that we trigger manually to set webhooks, we are looking to automate it!

I tried to use time resource but it seems not to provide such options. Trigger only once!

---
resources:
- name: only-once
  type: time
  icon: clock-outline
  source:
    interval: -0s #should never trigger again! Even after if we check reosurce

jobs:
- name: job
  public: true
  plan:
  - get: only-once
    trigger: true
  - task: simple-task
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: { repository: busybox }
      run:
        path: echo
        args: ["Hello, world!"]

https://github.com/concourse/time-resource

Am positive many would have crossed this path, am not sure what I am missing to get this automated fully.

EDIT:

Am trying to see if there are any way to trigger a build only once.

Example, setting of webhooks to a GiHub repo from concourse pipeline. Right now we create a pipeline --> go to the pipeline in ui --> trigger a job that sets the Webhook to the GitHub repo.

Rather than us triggering the job to set the webhook, are there any way we can make the pipeline know, its a new repo so the webhook job needs to be run once.

Kindly let me know if I need to add more detail!

2

There are 2 best solutions below

3
oozie _at_ concourse.farm On

Okay, got it! Your hunch regarding time resource was a good one. Let me riff on it to present a practical hack. Use a time resource with an interval of 99999h which translates to ~11 years. Consider the following pipeline:

one-off build kickoff

resources:
- name: kickoff
  type: time
  source:
    interval: 999999h

jobs:
- name: basically-run-only-once
  plan:
  - get: kickoff
    trigger: true
0
Anton Petrov On

To run a build only once, you can use the fly CLI:

jobs:
- name: run-once-job
  plan:
  ...

given your pipeline's name is one-off-pipeline:

fly -t team trigger-job -j one-off-pipeline/run-once-job

You can also choose to use tasks and run a task instead:

fly -t ps execute -c one-off-task.yml 

In case you want to automate this one-off task to run whenever you create a new repository, I guess you would need to write your own custom resource with that detection logic: https://concourse-ci.org/implementing-resource-types.html

Hope that helps.