Strengthening CI/CD pipelines with evidence-based email test receipts
A new approach to AWS CI/CD pipelines replaces simple pass/fail email tests with detailed promotion receipts that track build context, message ownership, and cleanup status.
In a recent technical deep-dive published on October 6, 2026, developer Jason Mills outlined a method for improving the reliability of email verification tests within AWS CI/CD pipelines. The article argues that standard boolean pass/fail results provide insufficient evidence for automated deployment decisions, leading to potential flakiness and unclear failure states. By introducing a structured "promotion receipt," teams can create an immutable record of each test attempt, ensuring that only verified and cleaned-up builds proceed to production.
What happened
The core issue addressed is the fragility of email testing in continuous integration environments. Traditionally, a test script might check if an email arrived and return a simple true or false value. However, this binary outcome hides critical context. A test might pass because it accidentally read a message from a previous retry, matched the wrong user in a shared inbox, or succeeded before properly cleaning up its test data. These hidden failures do not always trigger a red build status, allowing ambiguous states to persist.
To solve this, Mills proposes treating the email check as a transactional process that generates a JSON artifact, or "receipt," for every run. This receipt ties together the build ID, run ID, attempt number, fixture details, message ID, and cleanup status. Instead of relying solely on logs that may disappear when worker containers are terminated, the pipeline produces a persistent record. This allows engineers to audit exactly which message was consumed and whether the external test fixtures were properly removed, even after the build environment is gone.
Key details
- Structured Evidence: Each test run generates a JSON receipt containing the build ID, unique run and attempt IDs, correlation tokens, and the specific message ID matched.
- Deterministic Matching: Tests must match messages using recipient address, a unique correlation token, and message type, rather than simply selecting the newest email in an inbox.
- Explicit Cleanup States: The receipt tracks cleanup status with states such as
pending,cleaned, oralready_absent, ensuring that orphaned test data does not accumulate. - Retry Isolation: Retries generate new fixtures and attempt numbers instead of resetting old records, preventing late-arriving messages from being misattributed to a new attempt.
- Promotion Gates: Deployment jobs consume the receipt using tools like
jqto verify that the test passed, the message was uniquely identified, and cleanup was successful before allowing promotion. - Security Boundaries: The receipt stores only necessary metadata like message IDs and matching fields, excluding sensitive credentials or full message bodies to maintain security.
Background
For teams unfamiliar with advanced CI/CD patterns, it is helpful to understand the concept of "flaky tests." These are tests that non-deterministically pass or fail due to external factors like network latency, timing issues, or shared state. In email testing, flakiness often arises because mail servers may delay delivery, or multiple tests might compete for the same inbox. Without strict isolation, a test might claim success by reading an email intended for a different run.
The proposed solution leverages the concept of "idempotency" in cleanup operations. Idempotency means that performing an operation multiple times has the same effect as performing it once. In this context, deleting a test email should succeed whether the email is present or already gone. This prevents cleanup scripts from failing unnecessarily and ensures that the final state of the system is predictable. The "promotion receipt" acts as a bridge between the transient test environment and the permanent deployment decision, providing a verifiable chain of custody for the test data.
Why it matters
For engineering teams running their own software, particularly those using self-hosted CI/CD runners or managing complex AWS pipelines, reliability is paramount. A false positive in a test suite can lead to deploying broken code, while a false negative wastes developer time investigating non-existent bugs. By implementing promotion receipts, teams gain visibility into the root cause of test failures. Instead of guessing whether a timeout was due to a slow server or a logic error, engineers can inspect the receipt to see if the message was ever found or if cleanup failed.
This approach also enhances security and operational hygiene. By separating the permissions of the test role (which creates and deletes fixtures) from the promotion role (which only reads the receipt), teams reduce the blast radius of a compromised build worker. The deployment job does not need direct access to mailboxes or delete permissions; it only needs to trust the immutable artifact produced by the test. This principle of least privilege is crucial for maintaining secure infrastructure in small and mid-sized companies where resources are limited but security standards must remain high.
What you can do
- Implement Correlation Tokens: Modify your email tests to include a unique token in the subject or body of each test email, ensuring that you can definitively link a received message to a specific test run.
- Generate JSON Artifacts: Configure your CI pipeline to output a JSON file at the end of each test stage, capturing the build ID, attempt number, and test results in a structured format.
- Enforce Strict Matching: Update your email retrieval logic to require matches on recipient, token, and message type, rejecting any ambiguity rather than defaulting to the most recent message.
- Add Cleanup Verification: Ensure your test teardown steps explicitly report their status in the receipt, distinguishing between successful cleanup, already-absent resources, and actual failures.
- Gate Deployments on Receipts: Use shell commands or pipeline conditions to parse the promotion receipt, blocking deployment if the cleanup status is pending or if the message match is not unique.
- Schedule Sweepers: Implement a background job that periodically checks for and removes orphaned test fixtures that may have been left behind by cancelled builds or crashed workers.



