Excellent troubleshooting thread. Let me provide the comprehensive solution that addresses all the environment sync components:
1. Xray Environment Mapping Fix:
First, standardize your environment names in Xray Test Environments configuration. Ensure they match exactly (case-sensitive) with what your CI passes. Navigate to Xray settings → Test Environments and verify each environment name.
2. Custom Field Sync Configuration:
The environment custom field needs explicit mapping. Add this to your CI script:
curl -X PUT /rest/api/2/issue/{executionKey} \
-d '{"fields": {"customfield_10050": "Staging"}}'
Replace customfield_10050 with your actual environment field ID. This ensures the Jira custom field reflects the execution environment.
3. CI Parameter Passing:
Update your pipeline to use exact environment names:
xray_import_execution(
environment="Staging",
testPlanKey="TP-123"
)
Not lowercase, not IDs - exact string match to Xray configuration.
4. OSLC Adapter Configuration:
If using OSLC Connect or similar adapters, check the adapter’s environment mapping rules. Edit the adapter configuration file to remove hardcoded environment overrides:
# Remove or comment out:
# environment.default=dev
# environment.override=true
Set environment.passthrough=true to allow CI parameters to flow through.
5. Verification Steps:
- Create a test execution via API and immediately query the custom field value
- Check Xray execution details page to confirm environment badge matches
- Review CI logs for any environment parameter warnings
- Test with all three environments to ensure consistent behavior
Additional Considerations:
If you’re using Xray Cloud, note that environment handling differs slightly from Server/DC. Cloud uses a different API endpoint structure. Also, ensure your CI service account has permission to set custom fields - some organizations restrict this.
The key insight is that environment data flows through three layers: Xray’s internal environment registry, the API import parameters, and the Jira custom field. All three must align for proper sync. Most sync failures occur when one layer has different naming conventions or override rules.
After implementing these changes, your staging environment assignments should sync correctly, and QA validation workflows will reflect accurate environment tagging. The fix typically takes effect immediately without requiring Jira restart.