CircleCi动态config / config beartswand

发布于 2025-01-24 11:41:50 字数 479 浏览 3 评论 0原文

有人知道是否有可能将CircleCi的配置文件分解为每个作业,命令,工作流等的较小文件,它是在其自己的特定文件/子目录中,如果是的,您将如何处理?

我一直在环顾四周,甚至试图构建一个Python脚本来从所有这些YAML文件中构建配置,但是由于这些各种文件中未存在的参考变量名称而没有运气,因此Pyyaml库不会加载它们。

我要实现的是要拥有此文件夹结构

configs/
  dependencies.yml
  commands/
    command_1.yml
    command_2.yml
  jobs/
    job_1.yml
    job_2.yml
  workflows/
    workflow_1.yml
    workflow_2.yml

,其中dependencies.yml包含每个工作流程所需的内容,就每个步骤&gt中使用的内容而言; Job>命令。而且该文件将被手写。

Does anyone know if it's possible to breakdown the config file for circleci into smaller files where each job, command, workflow, etc, is in it's own specific file/subdirectory, and if so, how would you approach this?

I've been looking around and even attempted myself to build a python script to build a config from all these yaml files, but with no luck due to reference variable names not existing in these various files so pyyaml library won't load them.

What I'm trying to accomplish is to have this folder structure

configs/
  dependencies.yml
  commands/
    command_1.yml
    command_2.yml
  jobs/
    job_1.yml
    job_2.yml
  workflows/
    workflow_1.yml
    workflow_2.yml

Where dependencies.yml contains a breakdown of what each workflow requires in terms of what is used in each step > job > command. And this file would be hand written.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2025-01-31 11:41:50

您可以执行以下操作:


原始config.yml to Split:

version: 2
orbs:
  sonarcloud: sonarsource/[email protected]

jobs
  my-job:
    docker:
        - image: cimg/latest
    steps:
        - checkout
        - run: make

workflows:
  build:
    jobs:
      -my-job
  

在新文件夹中创建sufter conter contraut in New文件夹,称为config(run tree):

.
├── config.yml
└── config
    ├── @orbs.yml
    ├── jobs
    │   └──my-job.yml
    └── @workflows.yml

@orbs。 yml包含

version: 2
orbs:
  sonarcloud: sonarsource/[email protected]

@workflows.yml包含

workflows:
  build:
    jobs:
      -my-job

my-job.yml包含

docker:
  - image: cimg/latest
steps:
  - checkout
  - run: make

,主config.yml应该看起来像:

version: 2.1
setup: true
orbs:
  continuation: circleci/[email protected]

jobs:
  generate-and-run-circleci:
    docker:
      - image: 'circleci/circleci-cli:latest'
    steps:
      - circleci-cli/install
      - checkout
      - run:
          command : |
            cd .circleci
            circleci config pack config > generated.yml
      - continuation/continue:
          configuration_path: .circleci/generated.yml

workflows:
  build:
    jobs:
      - generate-and-run-circleci

You can do the following :

  • Split your config.yml in a structure defined in Packing a config
  • Use dynamic configuration where you fist generate the config from step 1 and the call the generated config file from them main file

Example original config.yml to split:

version: 2
orbs:
  sonarcloud: sonarsource/[email protected]

jobs
  my-job:
    docker:
        - image: cimg/latest
    steps:
        - checkout
        - run: make

workflows:
  build:
    jobs:
      -my-job
  

Create following layout in a new folder called config (run tree):

.
├── config.yml
└── config
    ├── @orbs.yml
    ├── jobs
    │   └──my-job.yml
    └── @workflows.yml

@orbs.yml contains

version: 2
orbs:
  sonarcloud: sonarsource/[email protected]

@workflows.yml contains

workflows:
  build:
    jobs:
      -my-job

my-job.yml contains

docker:
  - image: cimg/latest
steps:
  - checkout
  - run: make

And the main config.yml should look like:

version: 2.1
setup: true
orbs:
  continuation: circleci/[email protected]

jobs:
  generate-and-run-circleci:
    docker:
      - image: 'circleci/circleci-cli:latest'
    steps:
      - circleci-cli/install
      - checkout
      - run:
          command : |
            cd .circleci
            circleci config pack config > generated.yml
      - continuation/continue:
          configuration_path: .circleci/generated.yml

workflows:
  build:
    jobs:
      - generate-and-run-circleci
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文