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

如何让GitLab Runner读取指定文件替代.gitlab-ci.yml?

Can GitLab Runner (exec docker) read configuration files outside .gitlab-ci.yml?

Great question! The short answer is yes—you absolutely can get GitLab Runner (even when using the deprecated gitlab-runner exec docker command) to read configuration files beyond the default .gitlab-ci.yml. Here are a few practical approaches to make this work:

  • Specify an alternate main config file via command line
    Use the --config flag to tell the runner to use a different YAML file instead of .gitlab-ci.yml. For example:

    sudo gitlab-runner exec docker --config ./my-custom-ci-config.yml [job name]
    

    If you want to keep using .gitlab-ci.yml but add extra configs, newer Runner versions support the --include flag to pull in additional YAML files:

    sudo gitlab-runner exec docker --include ./ci-shared-templates.yml [job name]
    
  • Leverage the include keyword in .gitlab-ci.yml
    The standard GitLab CI include directive works perfectly with local exec runs too. Just add references to your external config files directly in your main .gitlab-ci.yml:

    include:
      - local: './ci-configs/deployment-jobs.yml'
      - local: './ci-configs/testing-templates.yml'
    

    When you run the exec docker command, the runner will parse all included files alongside the main config, just like it would on GitLab's hosted runners.

  • Mount non-YAML config files into the Docker container
    If your jobs need access to non-YAML files (like environment configs, script files, or tool settings), use the --volume flag to mount them from your host machine into the runner's Docker container:

    sudo gitlab-runner exec docker --volume /home/you/app-config.ini:/app/config.ini [job name]
    

    Your job scripts can then read this external file as if it were natively inside the container.

Note: As you pointed out, gitlab-runner exec is marked as deprecated, and there's no official replacement available yet. That said, all the methods above still work with the current version of GitLab Runner, so you can rely on them for local testing until a new solution is rolled out.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:43:32