On-Demand Build for Monorepo
About 162 wordsLess than 1 minute
This article will introduce how to trigger build tasks only for specific directories when modifying them in a Monorepo scenario, avoiding full builds to prevent resource waste and time consumption.
Key Concepts
- pipeline grammar: Pipeline.ifModify
- System default environment variables: CNB_PIPELINE_KEY
Example Configuration
.docker-build-pipeline:
&docker-build-pipeline # Use YAML anchors for configuration reuse
- services:
- docker # After declaration, docker commands can be used directly in the pipeline
ifModify:
- packages/${CNB_PIPELINE_KEY}/** # Specify that only modifications to files in this directory trigger the build. CNB_PIPELINE_KEY is a system default environment variable representing the current pipeline's KEY
stages:
- name: set docker tag
script: echo -n "${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:$CODING_COMMIT_SHORT"
exports:
info: IMAGE_TAG
- name: docker build
script: cd packages/${CNB_PIPELINE_KEY} && docker build -t $IMAGE_TAG .
- name: push image
script: docker push $IMAGE_TAG
master:
push:
package-1: *docker-build-pipeline
package-2: *docker-build-pipeline