screwdriver icon indicating copy to clipboard operation
screwdriver copied to clipboard

Setup & Teardown actions for Pipeline stages

Open jithine opened this issue 2 years ago • 5 comments

What happened:

Pipeline stages introduces logical grouping of various jobs, for example group all your production jobs as one stage of your build pipeline. It would be beneficial to provide setup and teardown actions for a Pipeline stage as a whole so that any initialization or cleanups needed before jobs in a stage runs can be executed. Idea is similar to the setup & teardown steps for an individual job

What you expected to happen:

Users should be able to define pre & post actions for a stage. UI should provide interface where users can see the logs for pre & post actions. Pre actions should run exactly once before any job in the stage runs. Post actions should run exactly once when a stage ends due to either success or failure of individual jobs. Pre & Post actions could be fashioned as jobs

Sub-Tasks:

  • [ ] https://github.com/screwdriver-cd/screwdriver/issues/3022
  • [x] https://github.com/screwdriver-cd/screwdriver/issues/3026
  • [x] https://github.com/screwdriver-cd/screwdriver/issues/3045

References:

Mocks - TBD

jithine avatar Sep 09 '22 17:09 jithine

cc @adong @tkyi

Alan pls share mocks with the actions mocked up

jithine avatar Sep 09 '22 17:09 jithine

Mocks: Screen Shot 2022-10-12 at 11 16 02 AM Screen Shot 2022-10-12 at 11 15 39 AM

tkyi avatar Oct 12 '22 18:10 tkyi

Some things for discussion:

Pre/postaction in stage

  • is this just another SD job, but it will always run (like how a setup/teardown step is just another SD step)?
  • can you rerun a pre/postaction job manually?
  • can you enable/disable a pre/postaction job?
  • job name ideas: pre/post{stage}, pre/postaction, setup/teardown{stage}, sd-setup-{stage}/sd-teardown-{stage}
  • what image will the job use? generic image, or will we let the user configure?
  • will we skip sd-setup-scm(git clone) step?

SD Config

Current stage config:

shared:
  image: node:14
  steps:
    - init: echo 'init'
jobs:
  job1:
    requires: [~pr, ~commit]
  job2:
    requires: [job1]
  job3:
    requires: [~pr, ~commit]
  job4:
    requires: [job3]

stages:
  seahorse:
    jobs: [job3, job4]
    description: "seahorse starfish deploy jobs"
  dolphin:
    jobs: [job2, job1]
    description: "dolphin deploy jobs"

Potential new:

shared:
  image: node:14
  steps:
    - init: echo 'init'
jobs:
  job1:
    requires: [~pr, ~commit]
  job2:
    requires: [job1]
  job3:
    requires: [~pr, ~commit]
  job4:
    requires: [job3]
  job5:
    image: alpine
    steps:
      - notify: set banner
  job6: 
    image: alpine
    steps:
      - announce: publish blog post

stages:
  seahorse:
    setup: job5
    jobs: [job3, job4]
    teardown: job6
    description: "seahorse starfish starfish deploy jobs"
  dolphin:
    jobs: [job2, job1]
    description: "dolphin deploy jobs"

stages:
  seahorse:
    setup: job5
    jobs: [job3, job4]
    teardown: job6
    description: "seahorse starfish deploy jobs"
  dolphin:
    jobs: [job2, job1]
    description: "dolphin deploy jobs"

Stage status

  • should it just be SUCCESS/FAILURE or should there be more granularity? (see https://github.com/screwdriver-cd/data-schema/blob/master/models/build.js#L16-L27)
  • if a pre/postaction job fails, will that stop the stage from continuing?

tkyi avatar Oct 31 '22 19:10 tkyi

@tkyi

is this just another SD job, but it will always run (like how a setup/teardown step is just another SD step)?

yes

can you rerun a pre/postaction job manually?

yes, no need to restrict a jobs behavior.

can you enable/disable a pre/postaction job?

yes

job name ideas: pre/post{stage}, pre/postaction, setup/teardown{stage}, sd-setup-{stage}/sd-teardown-{stage}

I like the setup & teardown, will be consistent with job's setup & teardown semantics.

what image will the job use? generic image, or will we let the user configure?

based on the proposal in the config, it looks like we can go with a full job config. which means users can configure every aspects of the pre/post stage including an image.

will we skip sd-setup-scm(git clone) step?

I am not sure if we need to skip, but I can see value in making it configurable and not do checkout by default But for a initial pass, we can consider pre/post actions as just a job, which would reduce the needs to have any custom workflow

should it just be SUCCESS/FAILURE or should there be more granularity? (see https://github.com/screwdriver-cd/data-schema/blob/master/models/build.js#L16-L27)

since we are modelling it after a job, any of the job's current status should be valid.

if a pre/postaction job fails, will that stop the stage from continuing?

yes

jithine avatar Nov 01 '22 22:11 jithine

After discussing with @jithine @sagar1312 this is the new proposed yaml below where a setup/teardown job will have all the characteristics of a job except it must be defined under stages and it cannot have keyword requires.

shared:
  image: node:14
  steps:
    - init: echo 'init'
jobs:
  job1:
    requires: [~pr, ~commit]
  job2:
    requires: [job1]
  job3:
    requires: [~pr, ~commit]
  job4:
    requires: [job3]

stages:
  seahorse:
    setup:
      image: alpine
      steps:
        - notify: set banner
    jobs: [job3, job4]
    teardown:
      image: alpine
      steps:
        - announce: publish blog post
    description: "seahorse starfish starfish deploy jobs"
  dolphin:
    jobs: [job2, job1]
    description: "dolphin deploy jobs"

tkyi avatar Nov 15 '22 21:11 tkyi

@sagar1312 @tkyi - I believe this is implemented, so can we close it?

VonnyJap avatar May 10 '24 05:05 VonnyJap

This has been implemented

sagar1312 avatar May 14 '24 16:05 sagar1312