On-Demand Build for Monorepo
About 163 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
- Syntax guide: Pipeline.ifModify
- System default environment variables: CNB_PIPELINE_KEY
Example Configuration
# Use YAML anchor for configuration reuse
.docker-build-pipeline: &docker-build-pipeline
services:
# Once declared, docker commands can be used directly within the pipeline
- docker
ifModify:
# Specifies that the build is triggered only when files in this directory are modified.
# Here, CNB_PIPELINE_KEY is a system default environment variable representing the current pipeline's KEY
- packages/${CNB_PIPELINE_KEY}/**
stages:
- name: set docker tag
script: echo -n "${CNB_DOCKER_REGISTRY}/${CNB_REPO_SLUG_LOWERCASE}:$CNB_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
main:
push:
package-1: *docker-build-pipeline
package-2: *docker-build-pipeline