조건
조건 (Kubernetes)
조건은 런타임에 파이프라인 스텝의 실행을 제한하는 데 사용할 수 있습니다. 예를 들어 브랜치를 기준으로 스텝 실행을 제한할 수 있습니다.
출처: Drone CI Docs
본문
kind: pipeline
type: kubernetes
name: default
steps:
- name: build
image: golang
commands:
- go build
- go test
when:
branch:
- master
- feature/*
조건에서 와일드카드 매칭을 사용할 수 있습니다. 조건은 정규표현식이 아닌 glob 패턴 매칭을 사용한다는 점에 유의하세요.
when:
ref:
- refs/heads/master
- refs/heads/**
- refs/pull/*/head
여러 조건을 조합할 수도 있습니다. 여러 조건을 조합할 때는 모든 조건이 true로 평가되어야 합니다.
when:
branch:
- master
event:
- push
브랜치 조건
branch 조건은 git 브랜치를 기준으로 스텝 실행을 제한합니다. pull request에서는 대상 브랜치가 평가되며, 태그 이벤트에서는 브랜치 이름을 사용할 수 없다는 점에 유의하세요.
브랜치 조건은 태그와 함께 사용할 수 없습니다. 태그는 그것이 생성된 소스 브랜치와 연관되지 않습니다.
when:
branch:
- master
- feature/*
include 문법 예시:
when:
branch:
include:
- master
- feature/*
exclude 문법 예시:
when:
branch:
exclude:
- master
- feature/*
이벤트 조건
event 조건은 Drone 이벤트 유형을 기준으로 스텝 실행을 제한합니다. push, pull request, 태그 등을 기준으로 스텝을 제한하고 싶을 때 유용합니다.
브랜치 조건은 태그 이벤트와 함께 사용할 수 없습니다. 태그는 그것이 생성된 소스 브랜치와 연관되지 않습니다.
when:
event:
- push
- pull_request
- tag
- promote
- rollback
include 문법 예시:
when:
event:
include:
- push
- pull_request
exclude 문법 예시:
when:
event:
exclude:
- pull_request
레퍼런스 조건
reference 조건은 git 레퍼런스 이름을 기준으로 스텝 실행을 제한합니다. 브랜치나 태그 이름을 glob 매칭하고 싶을 때 유용합니다.
when:
ref:
- refs/heads/feature-*
- refs/tags/*
include 문법 예시:
when:
ref:
include:
- refs/heads/feature-*
- refs/pull/**
- refs/tags/**
exclude 문법 예시:
when:
ref:
exclude:
- refs/heads/feature-*
- refs/pull/**
- refs/tags/**
리포지토리 조건
repository 조건은 리포지토리 이름을 기준으로 스텝 실행을 제한합니다. 리포지토리와 그 포크에 대해 Drone이 활성화되어 있고 이에 따라 실행을 제한하고 싶을 때 유용합니다.
when:
repo:
- octocat/hello-world
include 문법 예시:
when:
repo:
include:
- octocat/hello-world
- spacebhost/hello-world
exclude 문법 예시:
when:
repo:
exclude:
- octocat/hello-world
- spacebhost/hello-world
와일드카드 매칭 사용 예시:
when:
repo:
include:
- octocat/*
인스턴스 조건
instance 조건은 Drone 인스턴스 호스트명을 기준으로 스텝 실행을 제한합니다. 하나의 리포지토리에 여러 Drone 인스턴스가 설정되어 동일한 yaml 파일을 공유하면서, 인스턴스별로 스텝을 제한하고 싶을 때 유용합니다.
when:
instance:
- drone.instance1.com
- drone.instance2.com
include 문법 예시:
when:
instance:
include:
- drone.instance1.com
- drone.instance2.com
exclude 문법 예시:
when:
instance:
exclude:
- drone.instance1.com
- drone.instance2.com
와일드카드 매칭 사용 예시:
when:
instance:
include:
- *.company.com
상태 조건
status 조건은 파이프라인 상태를 기준으로 스텝 실행을 제한합니다. 예를 들어 실패할 때만 Slack 알림을 구성하고 싶을 수 있습니다.
when:
status:
- failure
실패 시 스텝을 실행합니다:
when:
status:
- failure
성공 또는 실패 시 스텝을 실행합니다:
when:
status:
- success
- failure
아래 설정은 중복입니다. 기본 동작은 파이프라인이 통과 상태일 때만 스텝이 실행되는 것입니다.
when:
status:
- success
대상(Target) 조건
target 조건은 대상 배포 환경을 기준으로 스텝 실행을 제한합니다. 이는 promotion과 rollback 이벤트에만 적용됩니다.
when:
target:
- production
include 문법 예시:
when:
target:
include:
- staging
- production
exclude 문법 예시:
when:
target:
exclude:
- production
크론(Cron) 조건
cron 조건은 파이프라인을 트리거한 cron 이름을 기준으로 스텝 실행을 제한합니다. 이는 cron 이벤트에만 적용됩니다.
when:
event:
- cron
cron:
- nightly
include 문법 예시:
when:
event:
- cron
target:
include:
- weekly
- nightly
exclude 문법 예시:
when:
event:
- cron
target:
exclude:
- nightly