Skip to main content

Action Runtime Information

When an action is running, it automatically prepares some environment variables and upstream helper steps to facilitate data exchange between the action and the platform.

Environment Variables

In addition to the system-reserved variables listed below, you may define your own variables for use at runtime.

Avoid naming collisions with the reserved variables to prevent unexpected errors.

Environment Variable NameValueDescription
COS_FILE_VOLUME/cos/filesMount directory for records
COS_CODE_VOLUME/cos/codesMount directory for code
COS_BIN_VOLUME/cos/binsMount directory for binary files
COS_BUNDLE_VOLUME/cos/bundlesMount directory for test programs in batch testing
COS_ARTIFACT_VOLUME/cos/artifactsArtifact directory for batch testing
COS_OUTPUT_VOLUME/cos/outputsOutput file directory for batch testing
COS_ORGIDORG UUIDORG ID
COS_USERIDUSER UUIDUSER ID
COS_WAREHOUSEIDWAREHOUSE UUIDWarehouse ID
COS_PROJECTPROJECT SLUGCurrent Action Running Project SLUG
COS_PROJECTIDPROJECT UUIDCurrent Action Running Project ID
COS_RECORDIDRECORD UUIDRecord ID
COS_ENDPOINTAPI URLcoScene API Endpoint
COS_TOKENCLI and API Token

Some of the above environment variables have empty values, which are optional. If they exist, their values are in UUID format; if not, they are empty.

COS_TOKEN

COS_TOKEN is automatically injected at startup.

Its permissions mirror those of the user who triggered the action. When performing cross-project operations, ensure the triggering user holds the required permissions on the target project; otherwise, related API calls will fail.

Using Output Directory to Create and Update Records

During action runtime, you can use COS_TOKEN to call OpenAPI or coCLI to perform almost all platform operations.

For common operations like creating and updating records, you can also output files according to a specified file structure, and the action runtime environment will automatically complete record creation and updates.

After the action finishes running, the platform will automatically scan the specific directory structure under COS_OUTPUT_VOLUME and automatically create or update records based on configuration files, while uploading related files.

Directory Structure Convention

Please organize files according to the following structure within the mounted COS_OUTPUT_VOLUME directory:

$COS_OUTPUT_VOLUME
└── records
├── record-directory-1/ # Any name
│ ├── front-001.jpg # Files to be uploaded
│ ├── front-002.jpg
│ └── .cos/
│ └── record.patch.json
└── record-directory-2/
├── rear-001.jpg
├── rear-002.jpg
└── .cos/
└── record.patch.json

Key requirements:

  • Each first-level subdirectory under /records represents a record operation.
  • Each record directory must contain a .cos/ subdirectory.
  • The .cos/ directory must contain a record.patch.json file.
  • Other files in the record directory will be automatically uploaded to the corresponding record.

Declaration File Format

record.patch.json defines record creation or update operations in the following format:

{
"projectSlug": "project-slug", // Optional, defaults to current project
"id": "record UUID", // Required for update or delete operations
"labels": [],
"title": "Record Title", // Required when creating records
"description": "Record Description", // Optional
// Other record properties, optional
"patch": [
// RFC 6902 JSON Patch standard
{ "op": "replace", "path": "/title", "value": "Cam-front (night)" },
{ "op": "add", "path": "/labels/-", "value": "night-run" },
{ "op": "remove", "path": "/labels/0" },
{ "op": "add", "path": "/files/path/to/file", "value": "../1.jpg" }
]
}

This JSON file mainly contains three parts:

  • Special properties: If you need to perform cross-project operations, specify projectSlug.
  • Regular properties: Describe basic record information. When no id is specified, it indicates creating a new record.
  • patch array: Provides fine-grained property modification control, following the RFC 6902 standard.