Skip to content

Hooks

Begin by setting the pipeline from the file job-and-task-hooks.yml, unpause the pipeline and trigger the job.

Here is the pipeline, for reference
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
task-config: &task-config
  platform: linux
  image_resource:
    type: registry-image
    source: { repository: busybox }

jobs:
  - name: job
    public: true
    plan:
      - task: successful-task
        config:
          << : *task-config
          run:
            path: sh
            args: ["-lc", "exit 0"]
        on_success:
          task: task-success
          config:
            << : *task-config
            run:
              path: echo
              args: ["This task succeeded!"]
        on_abort:
          task: task-aborted
          config:
            << : *task-config
            run:
              path: echo
              args: ["This task was aborted!"]
      - task: failing-task
        config:
          << : *task-config
          run:
            path: sh
            args: ["-lc", "exit 1"]
        on_failure:
          task: task-failure
          config:
            << : *task-config
            run:
              path: echo
              args: ["This task failed!"]
    on_success:
      task: job-success
      config:
        << : *task-config
        run:
          path: echo
          args: ["This job succeeded!"]
    on_failure:
      task: job-failure
      config:
        << : *task-config
        run:
          path: echo
          args: ["This job failed!"]
    on_abort:
      task: job-aborted
      config:
        << : *task-config
        run:
          path: echo
          args: ["This job was aborted!"]

Study the job configuration and try to reason through everything you see in the build output.

For example:

  • Why did the task-aborted task never run?
  • Or for that matter the task named job-success. Why did it never run?
  • Can you set up a situation where the task task-aborted actually does run? What would you have to do?

Use Cases

It is important for a CI/CD system such as Concourse to have a mechanism for hooks such as these, at both the job and step levels. For example, we might want to notify someone when a job fails.

A great exercise would be to use job hooks in conjunction with the slack-notifier resource type mockersf/concourse-slack-notifier to send a message to a Slack channel notifying your team that a job in your pipeline has failed.