0

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!

  • 1
    I read your question 3x and I'm not clear on what you're doing and where you're stuck. The title also unhelpful. Please rephrase your question along with the title for clarity. For example, remove any bits that are not strictly relevant, briefly describe a lifecycle of a process you're trying to automate, end with a clearly stated question. – oozie _at_ concourse.farm Mar 14 '23 at 19:34
  • Are you using the webhooks to trigger new builds in concourse on a new commit? To automatically trigger new builds when your repository changes you can use a git resource in combination with a `get` step with a `trigger`: https://concourse-ci.org/git-trigger-example.html – Anton Petrov Mar 16 '23 at 21:17
  • HI @oozie_at_concourse.farm, Please see my edit, let me know if I need to add more details! – Arun Senthoor Pandian Mar 18 '23 at 13:15
  • Hi @AntonPetrov, Hope now I am clear about my requirement! – Arun Senthoor Pandian Mar 18 '23 at 13:16

2 Answers2

1

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

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.

Anton Petrov
  • 684
  • 5
  • 14