You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10使用shell执行器运行GitLab CI出现if [[ -z "$CI_COMMIT_TAG" ]]报错

问题诊断

你的理解是错误的,该报错和CI_COMMIT_TAG标签配置无关。

报错根因

你看到的+ if [[ -z "$CI_COMMIT_TAG" ]]; then + ~ ...属于Bash语法的条件判断逻辑,触发错误的核心原因有两个:

  1. 你在config.toml中给https://gitlab.com/对应的私有Runner配置的执行器是shell,指定的shell类型是powershell,PowerShell原生不识别Bash的[[ ]]条件判断语法,运行时直接抛出语法错误
  2. 你的gitlab-ci.yml中给shell执行器的任务加了image字段配置:shell执行器是直接在Runner宿主机环境运行命令,不支持镜像拉取逻辑,该配置会触发GitLab CI默认的Bash预处理逻辑,进一步加剧语法冲突
解决方案

你可以根据自己的使用场景二选一:

方案一:继续使用PowerShell类型的Shell执行器

按如下要求调整配置:

  • 先在Windows 10的Runner宿主机上全局安装newman,配置好环境变量,保证本地PowerShell执行newman --version能正常返回版本号
  • 删掉gitlab-ci.yml中newman_tests任务下的所有image相关配置,调整后配置如下:
stages:
    - test

newman_tests:
    stage: test
    tags:
      # 如果你给AimoPractice这个Runner配置了标签,这里填对应标签即可;如果Runner开启了run_untagged可以省略
      - <your_runner_tag>
    shell: powershell
    script:
        - newman --version
        - newman run ./Postman_Collections/APIAutomation.json
  • (可选)如果你的Runner没有开启未打标签任务的执行权限,可以在config.toml对应的[[runners]]配置块下加run_untagged = true,或者给Runner配置专属标签后在job的tags字段匹配

方案二:改用Docker执行器(更推荐,不需要本地装newman)

如果你不想在本地宿主机配置newman环境,可以直接调整Runner的执行器类型:

  • 先在Windows 10环境安装好Docker Desktop,开启Linux容器模式
  • 修改config.toml中https://gitlab.com/对应Runner的配置,将executor = "shell"改为executor = "docker",新增Docker配置块如下:
[[runners]]
  name = "AimoPractice"
  url = "https://gitlab.com/"
  token = "<token>"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  • 原来的gitlab-ci.yml配置无需额外修改,直接运行流水线即可,Docker执行器会自动拉取postman/newman镜像执行任务

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 17:48:01