You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Cronicle插件的参数说明及添加方法技术咨询

Cronicle Plugin Parameters: Details & How to Add Them

I’ve worked with Cronicle quite a bit, so let’s walk through exactly how plugin parameters work and how to set them up properly.

1. How Parameters Are Passed to Plugins

Cronicle delivers parameters to your plugin in two reliable ways:

  • JSON Payload: The full set of parameters is sent as a JSON object to your plugin’s main script (typically via standard input, or directly through the job context if using the Node.js SDK).
  • Environment Variables: Every top-level parameter gets converted to an environment variable with the prefix CRONICLE_PARAM_. For example, a parameter named custom_path becomes CRONICLE_PARAM_custom_path.

Note: Nested parameter structures won’t get their own environment variables—you’ll need to parse the full JSON payload to access those values.

2. Step-by-Step: Adding Parameters to a Plugin

a. Define Parameters in Your Plugin Manifest

First, declare the parameters your plugin accepts in its plugin.json file. This tells Cronicle’s UI to render input fields for users to configure.

Here’s an example manifest snippet for a plugin that accepts a custom PATH and a debug flag:

{
  "id": "my_custom_tool",
  "name": "My Custom Plugin",
  "description": "Runs tasks with configurable environment and debug settings",
  "parameters": [
    {
      "name": "custom_path",
      "label": "Custom System PATH",
      "type": "text",
      "default": "/usr/local/bin:/usr/bin:/bin",
      "help": "Override the default PATH for this plugin's execution environment"
    },
    {
      "name": "debug_mode",
      "label": "Enable Debug Logging",
      "type": "boolean",
      "default": false,
      "help": "Turn on verbose output for troubleshooting"
    }
  ]
}

Supported parameter types include text, textarea, boolean, select, number, and more—refer to Cronicle’s internal docs for the full list.

b. Access Parameters in Your Plugin Script

Once parameters are defined, you can pull them into your executable script. Here are examples for common scripting languages:

Example (Bash Script)

Read the JSON payload from stdin or access environment variables directly:

#!/bin/bash
# Read full JSON parameter payload
PARAMS=$(cat -)

# Extract custom_path using jq (install jq if not present)
CUSTOM_PATH=$(echo "$PARAMS" | jq -r '.custom_path')
# Or grab it from the environment variable
CUSTOM_PATH_ENV=$CRONICLE_PARAM_custom_path

# Update the PATH for the plugin
export PATH="$CUSTOM_PATH:$PATH"

# Check debug mode
DEBUG_ENABLED=$(echo "$PARAMS" | jq -r '.debug_mode')
if [ "$DEBUG_ENABLED" = "true" ]; then
  echo "Debug mode active: Updated PATH to $PATH"
fi

# Rest of your plugin logic here...

Example (Node.js Script, Cronicle SDK)

Use the official SDK to access parameters directly from the job context:

const CroniclePlugin = require('cronicle-plugin');

class MyCustomPlugin extends CroniclePlugin {
  async run(job) {
    // Pull parameters from the job object
    const customPath = job.params.custom_path;
    const debugMode = job.params.debug_mode;

    // Override the system PATH
    process.env.PATH = `${customPath}:${process.env.PATH}`;

    if (debugMode) {
      this.log(`Debug mode enabled: PATH set to ${process.env.PATH}`);
    }

    // Execute your plugin's core functionality...
  }
}

module.exports = MyCustomPlugin;

c. Configure Parameters in a Cronicle Job

When creating or editing a job that uses your plugin, you’ll see the parameter fields you defined in the manifest. Fill in the desired values, and Cronicle will automatically pass them to your plugin when the job runs.

3. Common Use Cases for Plugin Parameters

  • Environment Customization: Like your PATH example, adjust variables to fit your plugin’s dependencies.
  • Dynamic Configuration: Let users input API keys, file paths, or thresholds without editing plugin code.
  • Feature Toggles: Use boolean parameters to enable/disable debug logging, dry runs, or optional features.

内容的提问来源于stack exchange,提问作者Hiba Rehman

火山引擎 最新活动