При работе с CI/CD (GitHub Actions, GitLab CI, Jenkins) часто нужно запускать пайплайн только при изменении определенных файлов. Это помогает оптимизировать сборку, экономить ресурсы и время.
🚩В GitHub Actions (on: push, paths)
В GitHub Actions можно указать файлы, изменения в которых запустят пайплайн.
name: Infra Pipeline
on:
push:
paths:
- 'infra/**'
- 'k8s/**'
pull_request:
paths:
- 'infra/**'
- 'k8s/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Deploy Infrastructure
run: ./deploy.sh
🚩В GitLab CI/CD (only: changes)
В GitLab можно настроить запуск пайплайна по изменению файлов с помощью
only: changes. stages:
- deploy
terraform:
stage: deploy
script:
- terraform apply -auto-approve
only:
changes:
- terraform/**
🚩В Jenkins (when { changes })
В Jenkins Declarative Pipeline можно использовать
when { changes } для проверки измененных файлов. pipeline {
agent any
stages {
stage('Deploy Ansible') {
when { changes path: 'ansible/**' }
steps {
sh './deploy_ansible.sh'
}
}
stage('Deploy Helm') {
when { changes path: 'helm/**' }
steps {
sh './deploy_helm.sh'
}
}
}
}Ставь 👍 и забирай 📚 Базу знаний