From 4c452c33bfa6688469aa45299680e9a45a19039f Mon Sep 17 00:00:00 2001 From: "fabiano.fernandes@stg.stackspot.com" Date: Mon, 9 Sep 2024 14:28:58 -0300 Subject: [PATCH] Add new workflow Gitlab Signed-off-by: fabiano.fernandes@stg.stackspot.com --- .gitlab-ci.yml.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ README-gitlab.md | 21 +++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .gitlab-ci.yml.yaml create mode 100644 README-gitlab.md diff --git a/.gitlab-ci.yml.yaml b/.gitlab-ci.yml.yaml new file mode 100644 index 0000000..2b73041 --- /dev/null +++ b/.gitlab-ci.yml.yaml @@ -0,0 +1,41 @@ +stages: + - cancel_run + +variables: + CLIENT_ID: $CLIENT_ID + CLIENT_KEY: $CLIENT_KEY + CLIENT_REALM: $CLIENT_REALM + RUN_ID: $RUN_ID + FORCE_CANCEL: ${FORCE_CANCEL:-'true'} + +cancel_run: + stage: cancel_run + script: + - echo "🤖 OS runner is $(uname)" + - git clone $CI_REPOSITORY_URL . + - apt-get update && apt-get install -y python3 python3-pip + - pip3 install requests + - | + cat < runtime.py + import os + import requests + + client_id = os.getenv('CLIENT_ID') + client_key = os.getenv('CLIENT_KEY') + client_realm = os.getenv('CLIENT_REALM') + run_id = os.getenv('RUN_ID') + force_cancel = os.getenv('FORCE_CANCEL') + + url = f"https://api.example.com/{client_realm}/runs/{run_id}/cancel" + headers = { + 'Authorization': f'Bearer {client_key}', + 'Content-Type': 'application/json' + } + data = { + 'force': force_cancel + } + + response = requests.post(url, headers=headers, json=data) + print(response.status_code, response.text) + EOF + - python3 runtime.py \ No newline at end of file diff --git a/README-gitlab.md b/README-gitlab.md new file mode 100644 index 0000000..2756b96 --- /dev/null +++ b/README-gitlab.md @@ -0,0 +1,21 @@ +# GitLab CI/CD Workflow for Runtime Cancel Run Action + +This GitLab CI/CD workflow runs the Runtime Cancel Run Action with the specified parameters. + +## Inputs + +The following environment variables must be configured in your GitLab CI/CD settings: + +- `CLIENT_ID`: Account client id (required) +- `CLIENT_KEY`: Account client secret key (required) +- `CLIENT_REALM`: Account client realm (required) +- `RUN_ID`: RUN_ID to cancel (required) +- `FORCE_CANCEL`: Forces the cancel (optional, default: `true`) + +## Usage + +To use this workflow, add the above environment variables to your GitLab CI/CD settings and include the `.gitlab-ci.yml` file in your repository. + +```yaml +include: + - local: '.gitlab-ci.yml' \ No newline at end of file