1---
2jobs:
3- name: retry-job
4  plan:
5  - &init-task
6    task: initial-output
7    config:
8      platform: linux
9
10      image_resource:
11        type: mock
12        source: {mirror_self: true}
13
14      outputs:
15      - name: attempts-log
16
17      run:
18        path: touch
19        args: ['attempts-log/attempts']
20  - &attempts-task
21    task: succeed-on-3rd-attempt
22    attempts: 5
23    config:
24      platform: linux
25      image_resource:
26        type: mock
27        source: {mirror_self: true}
28      inputs:
29      - name: attempts-log
30        path: old
31      outputs:
32      - name: attempts-log
33        path: new
34      run:
35        path: sh
36        args:
37        - -ec
38        - |
39          cp old/attempts new/
40
41          echo attempt >> new/attempts
42          attempts=$(cat new/attempts | wc -l)
43
44          echo $attempts > /tmp/retry_number
45          echo -n "attempts: $attempts; "
46
47          if [ $attempts -eq 3 ]; then
48            echo 'success!'
49          else
50            echo 'failing'
51            exit 1
52          fi
53
54- name: retry-job-fail-for-hijacking
55  plan:
56  - *init-task
57  - *attempts-task
58  - task: fail
59    config:
60      platform: linux
61
62      image_resource:
63        type: mock
64        source: {mirror_self: true}
65
66      run: {path: 'false'}
67