Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitlab-ci.yml.yaml
Original file line number Diff line number Diff line change
@@ -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 <<EOF > 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
21 changes: 21 additions & 0 deletions README-gitlab.md
Original file line number Diff line number Diff line change
@@ -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'