실행 컨텍스트 선택
GitLab v19.1일부 테스트는 특정 환경이나 특정 파이프라인 또는 job에 대해 실행되도록 설계되어 있습니다. :production과 { <switch>: 'value' }를 동시에 지정할 수 없습니다. 지정된 컨텍스트에서만 테스트를 실행합니다.
일부 테스트는 특정 환경이나 특정 파이프라인 또는 job에 대해 실행되도록 설계되어 있습니다. only 및 except 메타데이터를 사용하여 테스트 실행 컨텍스트를 지정할 수 있습니다.
사용 가능한 스위치#
| 스위치 | 기능 | 타입 |
|---|---|---|
| tld | 최상위 도메인 매처 설정 | String |
| subdomain | 서브도메인 매처 설정 | Array 또는 String |
| domain | 도메인 매처 설정 | String |
| production | 프로덕션 환경 매칭 | Static |
| pipeline | 파이프라인 매칭 | Array 또는 Static |
| job | job 매칭 | Array 또는 Static |
:production과 { <switch>: 'value' }를 동시에 지정할 수 없습니다.
이 옵션들은 상호 배타적입니다. production을 지정하고 싶다면
tld와 domain을 독립적으로 제어할 수 있습니다.
예시#
Only#
지정된 컨텍스트에서만 테스트를 실행합니다.
매칭 방법:
-
환경에는 정규식을 사용합니다.
-
파이프라인에는 문자열 매칭을 사용합니다.
-
job에는 정규식 또는 문자열 매칭을 사용합니다.
-
일반 조건에는 람다 또는 truthy/falsey 값을 사용합니다.
| 테스트 실행 컨텍스트 | 키 | 매칭 |
|---|---|---|
| gitlab.com | only: :production | gitlab.com |
| staging.gitlab.com | only: { subdomain: :staging } | (staging).+.com |
| gitlab.com 및 staging.gitlab.com | only: { subdomain: /(staging.)?/, domain: 'gitlab' } | (staging.)?gitlab.com |
| dev.gitlab.org | only: { tld: '.org', domain: 'gitlab', subdomain: 'dev' } | (dev).gitlab.org |
| staging.gitlab.com 및 domain.gitlab.com | only: { subdomain: %i[staging domain] } | (staging |
| nightly 파이프라인 | only: { pipeline: :nightly } | "nightly scheduled pipeline" |
| nightly 및 canary 파이프라인 | only: { pipeline: [:nightly, :canary] } | "nightly scheduled pipeline" 및 "canary" |
| ee:instance job | only: { job: 'ee:instance' } | 모든 파이프라인의 ee:instance job |
| quarantine으로 끝나는 모든 job | only: { job: '.*quarantine' } | 모든 파이프라인에서 quarantine으로 끝나는 모든 job |
| 로컬 개발 환경 | only: :local | Runtime::Env.running_in_ci?가 false인 모든 환경 |
| 조건이 truthy 값으로 평가되는 모든 실행 | only: { condition: -> { ENV['TEST_ENV'] == 'true' } } | TEST_ENV가 true로 설정된 모든 실행 |
RSpec.describe 'Area' do
it 'runs in any environment or pipeline' do; end
it 'runs only in production environment', only: :production do; end
it 'runs only in staging environment', only: { subdomain: :staging } do; end
it 'runs in dev environment', only: { tld: '.org', domain: 'gitlab', subdomain: 'dev' } do; end
it 'runs in prod and staging environments', only: { subdomain: /(staging.)?/, domain: 'gitlab' } {}
it 'runs only in nightly pipeline', only: { pipeline: :nightly } do; end
it 'runs in nightly and canary pipelines', only: { pipeline: [:nightly, :canary] } do; end
it 'runs in specific environment matching condition', only: { condition: -> { ENV['TEST_ENV'] == 'true' } } do; end
end
Except#
지정된 컨텍스트를 제외한 일반적인 컨텍스트에서 테스트를 실행합니다.
매칭 방법:
-
환경에는 정규식을 사용합니다.
-
파이프라인에는 문자열 매칭을 사용합니다.
-
job에는 정규식 또는 문자열 매칭을 사용합니다.
-
일반 조건에는 람다 또는 truthy/falsey 값을 사용합니다.
| 테스트 실행 컨텍스트 | 키 | 매칭 |
|---|---|---|
| gitlab.com | except: :production | gitlab.com |
| staging.gitlab.com | except: { subdomain: :staging } | (staging).+.com |
| gitlab.com 및 staging.gitlab.com | except: { subdomain: /(staging.)?/, domain: 'gitlab' } | (staging.)?gitlab.com |
| dev.gitlab.org | except: { tld: '.org', domain: 'gitlab', subdomain: 'dev' } | (dev).gitlab.org |
| staging.gitlab.com 및 domain.gitlab.com | except: { subdomain: %i[staging domain] } | (staging |
| nightly 파이프라인 | only: { pipeline: :nightly } | "nightly scheduled pipeline" |
| nightly 및 canary 파이프라인 | only: { pipeline: [:nightly, :canary] } | "nightly scheduled pipeline" 및 "canary" |
| ee:instance job | except: { job: 'ee:instance' } | 모든 파이프라인의 ee:instance job |
| quarantine으로 끝나는 모든 job | except: { job: '.*quarantine' } | 모든 파이프라인에서 quarantine으로 끝나는 모든 job |
| 조건이 truthy 값으로 평가되는 경우를 제외한 모든 실행 | except: { condition: -> { ENV['TEST_ENV'] == 'true' } } | TEST_ENV가 true로 설정되지 않은 모든 실행 |
RSpec.describe 'Area' do
it 'runs in any execution context except the production environment', except: :production do; end
it 'runs in any execution context except the staging environment', except: { subdomain: :staging } do; end
it 'runs in any execution context except the nightly pipeline', except: { pipeline: :nightly } do; end
it 'runs in any execution context except the ee:instance job', except: { job: 'ee:instance' } do; end
it 'runs in specific environment not matching condition', except: { condition: -> { ENV['TEST_ENV'] == 'true' } } do; end
end
사용 시 주의사항#
테스트에 before 또는 after 블록이 있는 경우, 외부 RSpec.describe 블록에 only 또는 except 메타데이터를 추가해야 합니다.
로컬 GitLab 인스턴스에서 only로 태그된 테스트를 실행하려면 다음 중 하나를 수행할 수 있습니다:
-
CI_PROJECT_NAME또는CI_JOB_NAME환경 변수가 설정되어 있지 않은지 확인합니다. -
메타데이터와 일치하도록 적절한 변수를 설정합니다. 예를 들어, 메타데이터가
only: { pipeline: :nightly }이면CI_PROJECT_NAME=nightly로 설정합니다. 메타데이터가only: { job: 'ee:instance' }이면CI_JOB_NAME=ee:instance로 설정합니다. -
메타데이터를 일시적으로 제거합니다.
로컬에서 except로 태그된 테스트를 실행하려면 다음 중 하나를 수행할 수 있습니다:
-
CI_PROJECT_NAME또는CI_JOB_NAME환경 변수가 설정되어 있지 않은지 확인합니다. -
메타데이터를 일시적으로 제거합니다.
특정 환경에 대한 테스트 격리(quarantine)#
특정 환경에서만 테스트를 실행하도록 지정하는 것과 마찬가지로, 특정 환경에서 실행될 때만 테스트를
격리(quarantine)하는 것도 가능합니다. 구문은 정확히 동일하며, 다만 only: { ... } 해시가
quarantine: { ... } 해시 안에 중첩됩니다.
예를 들어, quarantine: { only: { subdomain: :staging } }은 staging에 대해 실행될 때만 테스트를 격리합니다.
격리 기능은 GLCI_DISABLE_QUARANTINE 환경 변수를 사용하여 명시적으로 비활성화할 수 있습니다. 이는 로컬에서 테스트를 실행할 때 유용할 수 있습니다.