pipe-cd / pipecd

The One CD for All {applications, platforms, operations}
https://pipecd.dev
Apache License 2.0
1.09k stars 153 forks source link

Fix script run rollback #5204

Closed ffjlabo closed 3 weeks ago

ffjlabo commented 2 months ago

What this PR does / why we need it:

I fixed to finish executing the SCRIPT_RUN_ROLLBACK stage successfully when the pipeline has multiple SCRIPT_RUN stages.

Currently, the SCRIPT_RUN_ROLLBACK stage is predefined, and it is assumed that there are multiple in the pipeline. But we should modify the spec to execute only one SCRIPT_RUN_ROLLBACK. context: https://github.com/pipe-cd/pipecd/issues/5163#issuecomment-2333248785

PipeCD

app.pipecd.yaml

apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
  name: script-run-like-jenkins
  labels:
    env: example
    team: product
  pipeline:
    stages:
      - name: SCRIPT_RUN
        with:
          run: |
            sh script.sh
          onRollback: |
            echo rollback
      - name: SCRIPT_RUN
        with:
          run: |
            sleep 10
            sh script.sh
          onRollback: |
            echo $SR_DEPLOYMENT_ID
            echo $SR_APPLICATION_ID
            echo $SR_APPLICATION_NAME
            echo $SR_TRIGGERED_AT
            echo $SR_TRIGGERED_COMMIT_HASH
            echo $SR_REPOSITORY_URL
            echo $SR_SUMMARY
            echo $SR_CONTEXT_RAW
            sh script.sh
      - name: SCRIPT_RUN
        with:
          run: |
            sleep 10
            sh script.sh

  trigger:
    onChain:
      disabled: false
  description: |
    This app demonstrates how to use ANALYSIS stage to analyze the deployment.\
    After new version has been deployed to receive 10% of traffic, Piped periodically sends http requests to the endpoint of the new version to verify its responses.\
    References: [adding a new app](https://pipecd.dev/docs/user-guide/managing-application/adding-an-application/), [app configuration](https://pipecd.dev/docs/user-guide/configuration-reference/)

The execution flow

The example scenario is when canceling the last SCRIPT_RUN stage with above pipeline.

on planning

{
  "scriptRunBaseStageIDs": "stage-0,stage-1,stage-2",
  "scriptRun.stage-0.option": {"env":null,"run":"sh script.sh\n","timeout":"6h0m0s","onRollback":"echo rollback\n","skipOn":{}},
  "scriptRun.stage-1.option": {"env":null,"run":"sleep 10\nsh script.sh\n","timeout":"6h0m0s","onRollback":"echo $SR_DEPLOYMENT_ID\necho $SR_APPLICATION_ID\necho $SR_APPLICATION_NAME\necho $SR_TRIGGERED_AT\necho $SR_TRIGGERED_COMMIT_HASH\necho $SR_REPOSITORY_URL\necho $SR_SUMMARY\necho $SR_CONTEXT_RAW\nsh script.sh\n","skipOn":{}},
  "scriptRun.stage-2.option": {"env":null,"run":"sleep 10\nsh script.sh\n","timeout":"6h0m0s","onRollback":"","skipOn":{}},
}

on scheduling

{
  "scriptRunTargetStageIDs": "stage-0,stage-1,stage-2",
}

on deploying

Which issue(s) this PR fixes:

Fixes #5163

Does this PR introduce a user-facing change?:

github-actions[bot] commented 1 month ago

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 3 weeks ago

This PR was closed because it has been stalled for 7 days with no activity. Feel free to reopen if still applicable.