Test Policies
Automate test management with rules that run after each pipeline execution
Test Policies
Policies automate test management. Configure rules once, and Harness evaluates with every pipeline execution, automatically marking flaky tests or quarantining failures without manual intervention.
Prerequisites
Before using test policy commands, ensure you have:
Harness account access: Account, organization, and project IDs.
Personal Access Token (PAT): Required for API authentication. Go to Manage API keys to create a PAT.
hcli installed: Harness CLI tool must be available in your environment. Go to Install and configure Harness CLI to download hcli for your operating system and architecture.
Quick Start
Create a policy that auto-quarantines any failing test:
Policy Format
when
Array of conditions (all must match—AND logic)
action
Array of actions to execute when conditions match
You can define up to 10 policies per repository.
Available Conditions
test failed
Current execution
Test failed in this pipeline run
test is flaky
Historical
Test was previously detected as flaky
test is slow
Current execution
Test execution time exceeded threshold
Available Actions
mark flaky
Force test as flaky (overrides auto-detection)
unmark flaky
Clear any manual override—let auto-detection decide flaky status
mark unflaky
Force test as stable—ignores auto-detection even if test behavior is inconsistent
mark quarantine
Quarantine the test—failures won't block pipeline
unmark quarantine
Remove from quarantine
Policy Examples
Auto-Quarantine Failing Tests
Immediately quarantine any test that fails:
Mark Slow Tests as Flaky
Flag tests with timing issues:
Quarantine Flaky Failures
Only quarantine tests that are already flaky AND fail:
POLICY ORDER MATTERS
Policies are evaluated in order. Place quarantine rules before flaky rules when combining conditions. If a test is marked flaky by an earlier policy, a later policy checking test is flaky will match.
View Current Policies
Required Parameters
--account-id: Your Harness account ID--repo: Repository URL (with or without.gitsuffix)--endpoint: TI service endpoint URL--api-key: Your Personal Access Token (PAT) starting withpat.
Optional Parameters
--org-id: Organization ID (filters policies to a specific organization)--project-id: Project ID (filters policies to a specific project)
Example output:
Update Policies
policy set replaces all policies. Always include every policy you want active:
Clear All Policies
Running hcli Locally vs In Pipelines
In Harness Pipelines
Most environment variables are automatically available:
Running Locally (Administrators)
You must provide all parameters explicitly:
CLI Reference
policy set
--account-id
Yes
Harness account ID
--org-id
Yes
Organization ID
--project-id
Yes
Project ID
--repo
Yes
Repository URL (.git suffix optional, auto-appended)
--endpoint
Yes
TI service endpoint URL
--api-key
Yes
Personal Access Token (PAT) starting with pat.
--file
Yes
Path to JSON file (use - for stdin)
policy get
--account-id
Yes
Harness account ID
--repo
Yes
Repository URL (.git suffix optional, auto-appended)
--endpoint
Yes
TI service endpoint URL
--api-key
Yes
Personal Access Token (PAT) starting with pat.
--org-id
No
Organization ID (filters results to specific org)
--project-id
No
Project ID (filters results to specific project)
Best Practices
Version control your policies
Track changes, enable code review
Start conservative
Begin with lenient policies, tighten as needed
Review policy effects weekly
Ensure policies aren't over-quarantining
Document policy rationale
Help future admins understand intent
Next Steps
View quarantined tests affected by policies
View flaky tests detected by the system
Last updated
Was this helpful?