我有一个单库存储库,里面有很多需要分别部署的内容。
现在我想知道是否可能仅在推送标签且某个目录中有更改时运行任务。
我尝试了以下方法:
这是我使用的 .gitlab-ci.yml 文件之一。除了一些细微差别外,它们都看起来相同。
现在我想知道是否可能仅在推送标签且某个目录中有更改时运行任务。
我尝试了以下方法:
.components:
only:
changes:
- source/packages/components/**/*
except:
- branches
.components:
only:
refs:
- tags
changes:
- source/packages/components/**/*
.components:
rules:
- if: $CI_COMMIT_TAG
changes:
- source/packages/components/**/*
.components:
rules:
- if: $CI_COMMIT_TAG
changes:
- source/packages/components/**/*
when: always
- when: never
这是我使用的 .gitlab-ci.yml 文件之一。除了一些细微差别外,它们都看起来相同。
.components:
rules:
- if: '$CI_COMMIT_TAG'
changes:
- source/packages/components/**/*
build_componets:
stage: build
extends: .components
needs: []
script:
- echo "Compiling the components code..."
test_componets:
stage: test
extends: .components
needs: ["build_componets"]
script:
- echo "Compiling the components code..."
deploy_componets:
stage: deploy
extends: .components
needs: ["test_componets"]
script:
- echo "Compiling the components code..."
当前行为:每个流水线都会运行...而不考虑这些配置,但只有在我推送标签时才运行。
所有这些文件都被导入到项目根目录下的一个主文件中。
stages:
- build
- test
- deploy
include:
- source/packages/business-logic/.gitlab-ci.yml
- source/packages/components/.gitlab-ci.yml
- source/applications/native/.gitlab-ci.yml
- source/services/user-service/.gitlab-ci.yml
合并后的YAML如下所示。
---
".business-logic":
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/business-logic/**/*
when: always
- when: never
build_business_logic:
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/business-logic/**/*
when: always
- when: never
stage: build
extends: ".business-logic"
needs: []
script:
- yarn install
- yarn workspace @zeou/business-logic build
test_business_logic:
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/business-logic/**/*
when: always
- when: never
stage: test
extends: ".business-logic"
needs:
- build_business_logic
script:
- echo "Compiling the business-logics code..."
deploy_business_logic:
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/business-logic/**/*
when: always
- when: never
stage: deploy
extends: ".business-logic"
needs:
- test_business_logic
script:
- echo "Compiling the business-logics code..."
".components":
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/components/**/*
when: always
- when: never
build_components:
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/components/**/*
when: always
- when: never
stage: build
extends: ".components"
needs: []
script:
- echo "Compiling the components code..."
test_components:
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/components/**/*
when: always
- when: never
stage: test
extends: ".components"
needs:
- build_components
script:
- echo "Compiling the components code..."
deploy_components:
rules:
- if: "$CI_COMMIT_TAG"
changes:
- source/packages/components/**/*
when: always
- when: never
stage: deploy
extends: ".components"
script:
- echo "Compiling the components code..."
stages:
- ".pre"
- build
- test
- deploy
- ".post"
before_script:
有人能告诉我我做错了什么吗?
谢谢100次:D
when
关键字 https://dev59.com/3lIG5IYBdhLWcg3w_nTt#69551744 - farch