Middle
How to determine the startup parameters of a pipeline when editing specific resources in Git?
sobes.tech AI
Answer from AI
Using CI/CD triggers linked to changes in specific files or directories.
For example, in GitLab CI:
# .gitlab-ci.yml
stages:
- build
- test
build_job:
stage: build
script:
- echo "Building application..."
# Run pipeline only when files in the app/ directory change
only:
changes:
- app/**/*
test_job:
stage: test
script:
- echo "Running tests..."
# Run this stage only when tests in the test/ directory change
only:
changes:
- test/**/*
Maven in Jenkinsfile using the triggers directive:
// Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
}
// Trigger on changes in a specific directory (requires SCM API and Job DSL plugin)
// Example for Git with Poll SCM trigger
triggers {
pollSCM('H * * * *') // Poll every minute
}
options {
skipChanges() // Skip triggers if there are no changes
}
}
Using GitHub Actions:
# .github/workflows/ci.yml
name: CI Pipeline
on:
push:
# Run on changes in specific paths
paths:
- 'src/**'
- 'tests/**'
- '!docs/**' # Ignore changes in docs/ directory
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build
run: echo "Building..."
- name: Test
run: echo "Testing..."
This allows running only the necessary parts of the pipeline or the entire pipeline, saving computational resources and time. The exact syntax and capabilities depend on the specific CI/CD system.