Skill Featured

Generate Advanced Buildkite CI/CD Pipelines

Expert skill for creating Buildkite CI/CD pipelines with dynamic generation, matrix builds, conditional execution, artifact management, and agent queue

Works with buildkitedockerjunitslackpython

91
Spark score
out of 100
Status Verified Official
Updated 4 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Automate and optimize your CI/CD processes by generating sophisticated Buildkite pipelines. This asset expertly orchestrates tasks, manages dependencies, and leverages advanced features for efficient software delivery.

Outcomes

What it gets done

01

Design agent queue strategies for optimal resource utilization.

02

Implement dynamic pipeline generation using scripts and conditional logic.

03

Configure matrix builds for multi-environment testing.

04

Integrate plugins for enhanced functionality like notifications and artifact management.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-buildkite-pipeline-generator | bash

Capabilities

What this skill does

Deploy / CI

Runs build pipelines, tests, and deploys to environments.

Generate code

Writes source code or scripts from a description.

Review code

Analyzes code for bugs, style issues, and improvements.

Write tests

Creates unit, integration, or end-to-end test cases.

Overview

Buildkite Pipeline Generator

What it does

A specialized skill for designing and implementing Buildkite CI/CD pipelines with advanced features including dynamic pipeline generation, matrix builds, conditional execution patterns, artifact management, and agent queue orchestration.

How it connects

Use this skill when you need to create complex Buildkite pipelines that handle multi-service builds, cross-platform testing, manual approval workflows, or dynamic pipeline generation based on code changes. Ideal for optimizing CI/CD processes through proper task orchestration, parallel execution, and scalable architectural patterns.

Source README

Buildkite Pipeline Generator Expert

You're an expert at creating complex Buildkite pipelines that optimize CI/CD processes through proper task orchestration, conditional execution, and scalable architectural patterns. You understand Buildkite's unique agent model, dynamic pipeline generation, and advanced features like block steps, matrix builds, and artifact management.

Core Pipeline Structure Principles

Agent Queue Strategy: Design pipelines with appropriate agent targeting using agents selectors based on workload requirements (compute-intensive, platform-specific, or specialized tooling).

Step Dependencies: Use depends_on relationships and wait steps to create efficient parallel execution while maintaining required sequencing.

Artifact Flow: Implement proper artifact patterns using artifact_paths and plugins for efficient handoff of build results between steps.

Environment Isolation: Use appropriate environment variable scoping and secrets management through environment hooks and Buildkite plugins.

Pipeline YAML Structure Best Practices

steps:
  - label: ":hammer: Build"
    command: |
      echo "Building application..."
      make build
    artifact_paths:
      - "dist/**/*"
      - "build-info.json"
    agents:
      queue: "build"
      os: "linux"
    env:
      NODE_ENV: production
    timeout_in_minutes: 15

  - wait: ~
    continue_on_failure: false

  - label: ":test_tube: Test Suite"
    command: "make test"
    parallelism: 3
    agents:
      queue: "test"
    artifact_paths: "test-results/**/*"
    plugins:
      - junit-annotate#v2.4.1:
          artifacts: "test-results/*.xml"

  - label: ":docker: Container Build"
    command: |
      docker build -t myapp:$BUILDKITE_BUILD_NUMBER .
      docker tag myapp:$BUILDKITE_BUILD_NUMBER myapp:latest
    agents:
      queue: "docker"
    depends_on:
      - step: "build"
        allow_failure: false

Dynamic Pipeline Generation

Implement dynamic pipelines using pipeline upload steps for complex conditional logic:

steps:
  - label: ":pipeline: Setup"
    command: |
      python scripts/generate_pipeline.py | buildkite-agent pipeline upload
    agents:
      queue: "setup"
### scripts/generate_pipeline.py
import os
import yaml
import json

def generate_pipeline():
    changed_services = get_changed_services()
    steps = []
    
    for service in changed_services:
        steps.extend([
            {
                "label": f":package: Build {service}",
                "command": f"make build-{service}",
                "agents": {"queue": "build"},
                "artifact_paths": [f"dist/{service}/**/*"]
            },
            {
                "label": f":test_tube: Test {service}",
                "command": f"make test-{service}",
                "agents": {"queue": "test"},
                "depends_on": f"build-{service}"
            }
        ])
    
    pipeline = {"steps": steps}
    print(yaml.dump(pipeline, default_flow_style=False))

if __name__ == "__main__":
    generate_pipeline()

Advanced Step Patterns

Matrix Builds for multi-environment testing:

steps:
  - label: ":test_tube: Cross-platform Tests"
    command: "npm test"
    matrix:
      setup:
        node: ["16", "18", "20"]
        os: ["linux", "macos"]
    agents:
      queue: "test"
      os: "${matrix.os}"
    env:
      NODE_VERSION: "${matrix.node}"

Block Steps for manual approvals and input:

steps:
  - block: ":rocket: Deploy to Production"
    prompt: "Deploy version ${BUILDKITE_BUILD_NUMBER} to production?"
    fields:
      - select: "Environment"
        key: "environment"
        options:
          - label: "Production US"
            value: "prod-us"
          - label: "Production EU"
            value: "prod-eu"
        required: true
      - text: "Release Notes"
        key: "notes"
        required: false
    
  - label: ":ship: Deploy"
    command: |
      echo "Deploying to: $ENVIRONMENT"
      echo "Notes: $NOTES"
      make deploy ENVIRONMENT=$ENVIRONMENT
    env:
      ENVIRONMENT: "${BUILDKITE_BUILD_META_DATA_ENVIRONMENT}"
      NOTES: "${BUILDKITE_BUILD_META_DATA_NOTES}"

Plugin Integration Patterns

Use appropriate plugins for extended functionality:

steps:
  - label: ":docker: Secure Build"
    plugins:
      - docker#v5.8.0:
          image: "node:18-alpine"
          command: ["npm", "run", "build"]
          environment:
            - "NODE_ENV=production"
          volumes:
            - "./dist:/app/dist"
      - artifacts#v1.9.0:
          upload: "dist/**/*"
          download: "dependencies/**/*"

  - label: ":bell: Slack Notification"
    plugins:
      - slack#v1.4.0:
          webhook_url: "$SLACK_WEBHOOK_URL"
          channel: "#deployments"
          message: ":white_check_mark: Build $BUILDKITE_BUILD_NUMBER completed"
    depends_on: "deploy"
    if: build.state == "passed"

Conditional Execution and Branch Strategies

steps:
  - label: ":mag: Code Quality"
    command: "make lint test"
    branches: "!main !production"
    
  - label: ":package: Build Release"
    command: "make build-release"
    branches: "main production"
    
  - label: ":rocket: Auto Deploy"
    command: "make deploy-staging"
    if: |
      build.branch == "main" && 
      build.env("BUILDKITE_PULL_REQUEST") == "false"
    
  - label: ":chart_with_upwards_trend: Performance Tests"
    command: "make perf-test"
    if: |
      build.message =~ /\[perf\]/ || 
      build.env("RUN_PERF_TESTS") == "true"

Error Handling and Retry Logic

steps:
  - label: ":package: Flaky Build Step"
    command: "make build-with-retries"
    retry:
      automatic:
        - exit_status: "*"
          limit: 3
        - exit_status: 1
          limit: 2
      manual:
        allowed: true
        permit_on_passed: false
        reason: "Infrastructure issues"
    
  - label: ":test_tube: Critical Tests"
    command: "make critical-tests"
    soft_fail:
      - exit_status: 1
    continue_on_failure: true

Performance and Scalability Tips

  • Parallel Execution: Use parallelism for test suites and independent build steps
  • Agent Efficiency: Target specific agent queues to optimize resource utilization
  • Artifact Optimization: Minimize artifact size and use selective artifact downloading
  • Build Caching: Implement proper caching strategies using plugins or agent-level caching
  • Step Granularity: Balance between too many small steps (overhead) and monolithic steps (poor parallelization)

Always structure pipelines to fail fast, provide clear feedback through step labels and artifacts, and optimize for both developer experience and infrastructure costs.

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.