Read a CodePipeline or Amplify deploy’s checks from a later build

Proofline records a CodePipeline deploy only once the execution finishes. It records a success, and a failed, stopped or cancelled execution once it ties that execution to the ECS rollout that served the commit. A stage inside that execution cannot read its own deploy, so it waits until its timeout and exits 2. Start a separate reader when the execution succeeds and give it the execution ID so a redeploy of the same commit gets its own result. If the execution failed before a retry succeeded, the reader reads only the success, while the environment's Deploys tab keeps the failure.

Start CodeBuild when CodePipeline succeeds#

Bind the pipeline and its source action to the Proofline environment. Create a separate CodeBuild project for the reader in the pipeline’s region. Its build image needs the AWS CLI and a Proofline CLI whose proofline ci deploy --help lists --aws-run.

Create an EventBridge rule with this event pattern, replacing DeployProduction with the bound pipeline’s name. Choose the reader project as the target and give the rule permission to start it.

{
  "source": ["aws.codepipeline"],
  "detail-type": ["CodePipeline Pipeline Execution State Change"],
  "detail": {"pipeline": ["DeployProduction"], "state": ["SUCCEEDED"]}
}

In the target’s input transformer, map execution to $.detail.execution-id. Use this input template to pass the execution ID to the build.

{"environmentVariablesOverride":[{"name":"DEPLOY_EXECUTION","value":<execution>,"type":"PLAINTEXT"}]}

Read the deployed revision#

In the reader project, set PROOFLINE_ORGANIZATION_ID and ENVIRONMENT_ID to the Proofline organization and environment IDs. Set REPOSITORY to the connected GitHub repository in OWNER/NAME form. Create a token with Read reviews for that repository, store it in AWS Secrets Manager and bind it to the project variable PROOFLINE_TOKEN using the Secrets Manager variable type.

Give the build role access to that secret and to codepipeline:GetPipelineExecution for the bound pipeline. The buildspec below reads the full commit SHA from the execution that triggered the build. Replace DeployProduction and SourceArtifact with the pipeline name and the output artifact of the bound source action. If the pipeline has several sources, this selects the revision for the repository you named.

version: 0.2
phases:
  build:
    commands:
      - |
        set -eu
        commit=$(aws codepipeline get-pipeline-execution \
          --pipeline-name DeployProduction --pipeline-execution-id "$DEPLOY_EXECUTION" \
          --query "pipelineExecution.artifactRevisions[?name=='SourceArtifact'].revisionId | [0]" \
          --output text)
        if ! printf '%s' "$commit" | grep -Eqx '[0-9a-f]{40}'; then
          echo "No commit SHA for SourceArtifact in execution $DEPLOY_EXECUTION." >&2
          exit 1
        fi
        status=0
        proofline ci deploy --repo "$REPOSITORY" --commit "$commit" \
          --environment-id "$ENVIRONMENT_ID" --aws-run "$DEPLOY_EXECUTION" \
          --until landing --timeout 90 || status=$?
        case "$status" in
          0) echo "Landing checks recorded no regression." ;;
          2) echo "Result not established. Inspect the deploy before continuing." >&2 ;;
          3) echo "Deploy failed or regressed. Investigate before continuing." >&2 ;;
          *) echo "The reader could not complete the request." >&2 ;;
        esac
        exit "$status"

Set the CodeBuild project timeout above the reader’s 90-minute wait. This example fails the build when the execution has no commit SHA for the named artifact. It lets the build succeed on exit 0 and fails the build on other exits. Proofline prints the deploy link when it has recorded the run. The deploy checks reference explains the checkpoints and exit codes.

Read an Amplify Hosting job#

After a job on the bound Amplify branch succeeds, give the reader the full commit SHA and the job ID from that job. Use the same token and exit handling. Substitute the job ID for the CodePipeline execution ID.

proofline ci deploy --repo "$REPOSITORY" --commit "$DEPLOYED_COMMIT" \
  --environment-id "$ENVIRONMENT_ID" --aws-run "$AMPLIFY_JOB_ID" --until landing

If several Amplify jobs for that commit in the same Proofline environment share a job ID, the command includes the checks of every match.

Search help

Tab to a result. Enter to open. Escape to close.