Skip to content

Commit 5586013

Browse files
Fix E2E test trigger (#1214)
## Overview Change how the E2E tests are triggered. Launches pipelines for `amd64` and `amd64, fips` flavors, will add tests for `arm64` and `arm64, fips` as well if these work as expected. ## Testing E2E tests pass on this PR
1 parent 5b70f89 commit 5586013

2 files changed

Lines changed: 53 additions & 74 deletions

File tree

.gitlab/scripts/poll_e2e.sh

Lines changed: 34 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,52 @@
1-
#!/usr/bin/env bash
2-
# Trigger serverless-e2e-tests pipeline and poll until completion.
3-
4-
set -euo pipefail
5-
6-
if [ -z "${EXTENSION_LAYER_ARN:-}" ]; then
7-
echo "ERROR: EXTENSION_LAYER_ARN is not set or empty"
8-
exit 1
9-
fi
10-
11-
E2E_PROJECT_ENCODED="DataDog%2Fserverless-e2e-tests"
12-
E2E_REF="${E2E_REF:-main}"
13-
14-
curl -OL "binaries.ddbuild.io/dd-source/authanywhere/LATEST/authanywhere-linux-amd64" && mv authanywhere-linux-amd64 /bin/authanywhere && chmod +x /bin/authanywhere
1+
#!/bin/bash
2+
curl -OL "binaries.ddbuild.io/dd-source/authanywhere/LATEST/authanywhere-linux-amd64" \
3+
&& mv "authanywhere-linux-amd64" /bin/authanywhere \
4+
&& chmod +x /bin/authanywhere
155

166
BTI_CI_API_TOKEN=$(authanywhere --audience rapid-devex-ci)
177

188
BTI_RESPONSE=$(curl --silent --request GET \
199
--header "$BTI_CI_API_TOKEN" \
2010
--header "Content-Type: application/vnd.api+json" \
21-
"https://bti-ci-api.us1.ddbuild.io/internal/ci/gitlab/token?owner=DataDog&repository=serverless-e2e-tests")
11+
"https://bti-ci-api.us1.ddbuild.io/internal/ci/gitlab/token?owner=DataDog&repository=datadog-lambda-extension")
2212

2313
GITLAB_TOKEN=$(echo "$BTI_RESPONSE" | jq -r '.token // empty')
14+
2415
if [ -z "$GITLAB_TOKEN" ]; then
2516
echo "ERROR: could not obtain GitLab token from BTI"
2617
exit 1
2718
fi
2819

29-
echo "Triggering DataDog/serverless-e2e-tests pipeline (ref: ${E2E_REF})..."
30-
echo " EXTENSION_LAYER_ARN=${EXTENSION_LAYER_ARN}"
31-
32-
TRIGGER_RESPONSE=$(curl --silent --request POST \
33-
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
34-
--header "Content-Type: application/json" \
35-
--data "$(jq -n \
36-
--arg ref "$E2E_REF" \
37-
--arg arn "$EXTENSION_LAYER_ARN" \
38-
'{ref: $ref, variables: [{key: "EXTENSION_VERSION", value: $arn}]}')" \
39-
"${CI_API_V4_URL}/projects/${E2E_PROJECT_ENCODED}/pipeline")
20+
URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/bridges"
4021

41-
PIPELINE_ID=$(echo "$TRIGGER_RESPONSE" | jq -r '.id // empty')
42-
PIPELINE_URL=$(echo "$TRIGGER_RESPONSE" | jq -r '.web_url // empty')
43-
44-
if [ -z "$PIPELINE_ID" ] || [ "$PIPELINE_ID" = "null" ]; then
45-
echo "ERROR: failed to trigger downstream pipeline"
46-
echo "Response: $TRIGGER_RESPONSE"
47-
exit 1
48-
fi
49-
50-
echo "Triggered downstream pipeline: ${PIPELINE_URL} (ID: ${PIPELINE_ID})"
22+
echo "Fetching E2E job status from: $URL"
5123

5224
while true; do
53-
STATUS=$(curl --silent \
54-
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
55-
"${CI_API_V4_URL}/projects/${E2E_PROJECT_ENCODED}/pipelines/${PIPELINE_ID}" \
56-
| jq -r '.status // empty')
57-
58-
echo -n "E2E pipeline ${PIPELINE_ID} status: ${STATUS}, "
59-
60-
case "$STATUS" in
61-
success)
62-
echo "E2E tests passed"
63-
exit 0
64-
;;
65-
failed)
66-
echo "E2E tests failed"
67-
exit 1
68-
;;
69-
canceled|canceling)
70-
echo "E2E tests canceled"
71-
exit 1
72-
;;
73-
skipped)
74-
echo "E2E tests skipped"
75-
exit 0
76-
;;
77-
running|pending|created|waiting_for_resource|preparing)
78-
echo "still running, checking again in 2 minutes..."
79-
;;
80-
*)
81-
echo "unknown status, checking again in 2 minutes..."
82-
;;
83-
esac
84-
25+
HTTP_STATUS=$(curl -s -o /tmp/e2e_response.json -w "%{http_code}" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" "$URL")
26+
if [ "$HTTP_STATUS" != "200" ]; then
27+
echo "WARNING: GitLab API returned HTTP $HTTP_STATUS, retrying in 2 minutes..."
28+
sleep 120
29+
continue
30+
fi
31+
RESPONSE=$(cat /tmp/e2e_response.json)
32+
E2E_JOB_STATUS=$(echo "$RESPONSE" | jq -r --arg name "$E2E_JOB_NAME" '.[] | select(.name==$name) | .downstream_pipeline.status')
33+
echo -n "E2E job status: $E2E_JOB_STATUS, "
34+
if [ "$E2E_JOB_STATUS" == "success" ]; then
35+
echo "E2E tests completed successfully"
36+
exit 0
37+
elif [ "$E2E_JOB_STATUS" == "failed" ]; then
38+
echo "E2E tests failed"
39+
exit 1
40+
elif [ "$E2E_JOB_STATUS" == "running" ]; then
41+
echo "E2E tests are still running, retrying in 2 minutes..."
42+
elif [ "$E2E_JOB_STATUS" == "canceled" ]; then
43+
echo "E2E tests were canceled"
44+
exit 1
45+
elif [ "$E2E_JOB_STATUS" == "skipped" ]; then
46+
echo "E2E tests were skipped"
47+
exit 0
48+
else
49+
echo "Unknown E2E test status: $E2E_JOB_STATUS, retrying in 2 minutes..."
50+
fi
8551
sleep 120
8652
done

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ publish layer [self-monitoring] ({{ $flavor.name }}):
231231
{{ end }} # end flavors
232232

233233
{{ range $f := (ds "flavors").flavors }}
234-
{{ if $f.needs_layer_publish }}
234+
{{ if and $f.needs_layer_publish (eq $f.arch "amd64") }}
235235
{{- $dotenvE2E := printf "%s_sandbox_e2e.env" $f.suffix }}
236236
{{ with $environment := (ds "environments").environments.sandbox }}
237237

@@ -270,20 +270,33 @@ publish layer e2e sandbox ({{ $f.name }}):
270270
script:
271271
- .gitlab/scripts/publish_layers.sh
272272

273-
e2e-suite ({{ $f.name }}):
273+
e2e-test ({{ $f.name }}):
274274
stage: e2e
275-
image: registry.ddbuild.io/images/docker:20.10-py3
276-
tags: ["arch:amd64"]
277-
timeout: 3h
275+
trigger:
276+
project: DataDog/serverless-e2e-tests
277+
strategy: depend
278278
rules:
279-
# Do not block on release, in case E2E is flaky
280279
- if: '$CI_COMMIT_TAG =~ /^v.*/'
281280
when: on_success
282281
allow_failure: true
283282
- when: on_success
284283
needs:
285284
- job: "publish layer e2e sandbox ({{ $f.name }})"
286285
artifacts: true
286+
variables:
287+
EXTENSION_VERSION: $EXTENSION_LAYER_ARN
288+
ARCHITECTURE: {{ $f.arch }}
289+
290+
e2e-test-status ({{ $f.name }}):
291+
stage: e2e
292+
image: registry.ddbuild.io/images/docker:20.10-py3
293+
tags: ["arch:amd64"]
294+
timeout: 3h
295+
variables:
296+
E2E_JOB_NAME: "e2e-test ({{ $f.name }})"
297+
needs:
298+
- job: "publish layer e2e sandbox ({{ $f.name }})"
299+
artifacts: false
287300
script:
288301
- .gitlab/scripts/poll_e2e.sh
289302

0 commit comments

Comments
 (0)