Skip to content

任务定义与步骤 ​

最小定义 ​

json
{
  "key": "hula-recon",
  "name": "HuLa 环境勘察",
  "description": "一次性运维作业:只读勘察主机、服务与端口",
  "workdir": "/srv/deploy/workspaces/hula-recon",
  "timeoutSec": 600,
  "steps": [
    { "name": "主机与工具", "scriptFile": "sh/01-host.sh" },
    { "name": "服务状态", "scriptFile": "sh/02-services.sh" }
  ]
}

字段总表 ​

字段类型说明
key / name / descriptionstring标识、显示名、备注
workdirstring默认 ${WORKSPACE_ROOT}/${TASK_KEY}
shellstringauto 同项目解析规则
concurrencystringqueue / allow / cancelPrev
timeoutSecint整体超时,0 不限时
hookEnabledbool允许 Hook 触发
allowEnvOverridebool允许触发参数覆盖变量
stepsobject[]有序步骤,结构同项目命令
envsobject[]{key,value,isSecret}
archivedbool归档标记

没有 useGit/git*、kind/dependencies 字段——任务不接受 Git 与依赖语义。

只读返回:id、stepCount、ownerName、canEdit、lastRunAt/lastRunStatus、runCount、时间戳。

步骤对象 ​

与项目命令同构:name、script(或 CLI 定义侧 scriptFile)、sortOrder、enabled、 failStrategy(abort/continue)、workdirOverride、timeoutSec、shellOverride。

区别在存储与 ID:

  • 步骤内联整体保存,没有单条步骤的 CRUD 接口;--file 带 steps 即整体替换。
  • 步骤 ID 为位置序号(sortOrder 顺序,1 起),详见 步骤 ID 与选择性执行。

创建与更新 ​

bash
deploy task create --key clear-cache --name 清缓存 --workdir /srv/ops --step "redis-cli flushdb"
deploy task create --file task.json
deploy task update clear-cache --file task.json    # 只改文件里给出的字段;steps 整体替换
deploy task get clear-cache

update 保留未传字段;env 简写被拒绝(同项目,必须 envs)。 scriptFile 相对 JSON 目录解析、CRLF 归一化。

运行 ​

bash
deploy task run clear-cache -f
deploy task run clear-cache --step-id 2 -f
deploy task run clear-cache -e SCOPE=session --wait --json

task run 拒绝 --with-dependencies 与 --branch(任务无此语义,传入报用法错误)。 其余 flag(-f/--wait/-e/--cancel-on-interrupt/--json)与 run 一致。

设计建议 ​

  • 勘察类步骤保持只读;破坏性步骤(rm、覆盖配置、重启)单独成步并先 preview。
  • 步骤命名带序号前缀(01-主机、02-服务),与位置 ID 对应,便于 --step-id 记忆。
  • 配置类任务的脚本应幂等:重复执行不产生副作用(备份后再 sed、存在则跳过)。