Skip to content

Commit edf5718

Browse files
authored
Use gitlab's multi-project pipelines to trigger agent build (#19130)
* Use gitlab's multi-project pipelines to trigger agent build * fix "only" section * switch from only to rules * Fix variables * fix compare to * hardcode compare_to target * explain why we hardcode compare_to * remove old stages * fix and speed up logs pipeline validation * add job to validate agent build * remove validation step, default pipeline check is enough * support triggering manually from any branch * fix rules * don't require manual build step in order for pipeline to pass * add job to show pipeline as failed if manual trigger fails * remove "validation" job, it won't do what we think it should
1 parent fd0bf69 commit edf5718

File tree

5 files changed

+48
-265
lines changed

5 files changed

+48
-265
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include:
22
- /.gitlab/software_composition_analysis.yaml
3+
- /.gitlab/build_agent.yaml
34

45
variables:
56
TAGGER_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/integrations-core:tagger
@@ -13,9 +14,8 @@ variables:
1314

1415
stages:
1516
- build
16-
- trigger
17-
- release
1817
- validate
18+
- release
1919
- notify
2020

2121
cache: &slack-cache
@@ -26,6 +26,7 @@ cache: &slack-cache
2626

2727
validate-log-integrations:
2828
stage: validate
29+
needs: []
2930
image: $VALIDATE_LOG_INTGS
3031
only:
3132
- schedules
@@ -46,89 +47,9 @@ validate-log-integrations:
4647
when: always
4748
tags: [ "runner:main" ]
4849

49-
trigger-agent-build:
50-
stage: trigger
51-
image: $VALIDATE_AGENT_BUILD
52-
rules:
53-
# Never trigger for tag pipelines
54-
- if: $CI_COMMIT_TAG
55-
when: never
56-
# Trigger on non-release branches
57-
- if: ($CI_COMMIT_BRANCH !~ /^7.[0-9]{2}.x/)
58-
when: always
59-
cache:
60-
<<: *slack-cache
61-
script:
62-
- export SLACK_CACHE_DIR="${PWD}/.slack-cache"
63-
- DATADOG_AGENT_PIPELINE_URL=$(aws ssm get-parameter --region us-east-1 --name ci.integrations-core.datadog-agent-pipeline-url --with-decryption --query "Parameter.Value" --out text)
64-
- export DEPENDENCIES_CHANGED="false"
65-
- git fetch origin master
66-
- BASE_REF=$(git merge-base HEAD FETCH_HEAD)
67-
- git --no-pager diff --exit-code --name-only HEAD $BASE_REF -- .deps || export DEPENDENCIES_CHANGED="true" || true
68-
- export RELEASE_BRANCH=""
69-
- |
70-
if [[ "$DEPENDENCIES_CHANGED" = "true" ]]; then
71-
export RELEASE_BRANCH=$(git tag -l '7\.*' --points-at $BASE_REF | cat | sed 's/\..-.*/\.x/')
72-
echo "Dependency files under .deps have been modified, triggering an agent build pipeline."
73-
DATADOG_AGENT_PIPELINE_URL=$DATADOG_AGENT_PIPELINE_URL RELEASE_BRANCH=$RELEASE_BRANCH python -u /trigger_agent_build.py --output-file pipeline_id.txt
74-
75-
# Get slack user
76-
if [[ $GITLAB_USER_LOGIN = "codesync" ]]; then EMAIL=$(git show -s --format="%ae" "$CI_COMMIT_SHA"); else EMAIL=$GITLAB_USER_EMAIL; fi
77-
SLACK_AUTHOR=$(echo $EMAIL | email2slackid)
78-
if [ -z "$SLACK_AUTHOR" ]; then echo "${EMAIL} cannot be translated into a Slack user, defaulting to ${AGENT_BUILD_NOTIFICATIONS_SLACK_CHANNEL}"; SLACK_AUTHOR=$AGENT_BUILD_NOTIFICATIONS_SLACK_CHANNEL; fi
79-
80-
MESSAGE="Starting a build of the agent, watch ${CI_PIPELINE_URL}."
81-
postmessage "$SLACK_AUTHOR" "$MESSAGE"
82-
else
83-
echo "Nothing to run, skipping job."
84-
fi
85-
artifacts:
86-
paths:
87-
- pipeline_id.txt
88-
expire_in: 1 day
89-
when: always
90-
tags: [ "runner:main" ]
91-
92-
93-
validate-agent-build:
94-
stage: validate
95-
image: $VALIDATE_AGENT_BUILD
96-
timeout: 3 hours
97-
cache:
98-
<<: *slack-cache
99-
script:
100-
- export SLACK_CACHE_DIR="${PWD}/.slack-cache"
101-
- |
102-
if [[ -s ./pipeline_id.txt ]]; then
103-
# Fetch secrets from SCM
104-
GITLAB_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.integrations-core.temp_gitlab_token --with-decryption --query "Parameter.Value" --out text)
105-
DATADOG_AGENT_PIPELINE_URL=$(aws ssm get-parameter --region us-east-1 --name ci.integrations-core.datadog-agent-pipeline-url --with-decryption --query "Parameter.Value" --out text)
106-
PIPELINE_ID=$(cat pipeline_id.txt)
107-
108-
# Get slack user
109-
if [[ $GITLAB_USER_LOGIN = "codesync" ]]; then EMAIL=$(git show -s --format="%ae" "$CI_COMMIT_SHA"); else EMAIL=$GITLAB_USER_EMAIL; fi
110-
SLACK_AUTHOR=$(echo $EMAIL | email2slackid)
111-
if [ -z "$SLACK_AUTHOR" ]; then echo "${EMAIL} cannot be translated into a Slack user, defaulting to ${AGENT_BUILD_NOTIFICATIONS_SLACK_CHANNEL}"; SLACK_AUTHOR=$AGENT_BUILD_NOTIFICATIONS_SLACK_CHANNEL; fi
112-
113-
# Wait for the agent build to complete
114-
export BUILD_SUCCESS="true"
115-
GITLAB_TOKEN=$GITLAB_TOKEN DATADOG_AGENT_PIPELINE_URL=$DATADOG_AGENT_PIPELINE_URL python -u /validate_agent_build.py --pipeline-id $(cat pipeline_id.txt) || export BUILD_SUCCESS="false" || true
116-
echo $BUILD_SUCCESS
117-
if [[ "$BUILD_SUCCESS" = "true" ]]; then
118-
echo "Agent build was successful!"
119-
postmessage "$SLACK_AUTHOR" "Build ${CI_JOB_URL} was successful, you can merge your PR!" success
120-
else
121-
echo "Agent build failed."
122-
postmessage "$SLACK_AUTHOR" "The build failed, you might want to retry this job: ${CI_JOB_URL}" alert
123-
exit 1
124-
fi
125-
else
126-
echo "A pipeline was not triggered, skipping this job."
127-
fi
128-
129-
tags: [ "runner:main" ]
130-
13150
notify-slack:
51+
needs:
52+
- validate-log-integrations
13253
stage: notify
13354
image: $NOTIFIER_IMAGE
13455
only:
@@ -232,18 +153,3 @@ validate-log-intgs-builder:
232153
- cd .gitlab/validate-logs-intgs/
233154
- docker buildx build --tag $VALIDATE_LOG_INTGS . --push
234155
tags: [ "arch:amd64" ]
235-
236-
validate-agent-build-builder:
237-
stage: build
238-
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:24.0.4-gbi-focal
239-
only:
240-
changes:
241-
- .gitlab/validate-agent-build/**/*
242-
- .gitlab-ci.yml
243-
refs:
244-
- master
245-
script:
246-
- cd .gitlab/validate-agent-build/
247-
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/Datadog/devtools.git --depth 1
248-
- docker buildx build --tag $VALIDATE_AGENT_BUILD . --push
249-
tags: [ "arch:amd64" ]

.gitlab/build_agent.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
.build-agent-tpl:
3+
variables:
4+
_AGENT_BRANCH: main # Used only by this job
5+
# Pass these to triggered agent build job.
6+
RELEASE_VERSION_6: "nightly"
7+
RELEASE_VERSION_7: "nightly-a7"
8+
BUCKET_BRANCH: "dev"
9+
DEPLOY_AGENT: "false"
10+
INTEGRATIONS_CORE_VERSION: ${CI_COMMIT_REF_NAME}
11+
# disable kitchen and e2e tests
12+
RUN_KITCHEN_TESTS: "false"
13+
RUN_E2E_TESTS: "off"
14+
stage: build
15+
trigger:
16+
project: DataDog/datadog-agent
17+
branch: ${_AGENT_BRANCH}
18+
# It's more convenient to directly show if downstream pipeline succeeded.
19+
strategy: depend
20+
21+
build-agent-auto:
22+
extends: .build-agent-tpl
23+
rules:
24+
- changes:
25+
# We don't yet support variable expansion in `compare_to`. It was added in gitlab 17.2:
26+
# https://gitlab.com/gitlab-org/gitlab/-/issues/369916#note_1972773223
27+
compare_to: "master"
28+
paths:
29+
- .deps/*
30+
- .gitlab/build_agent.yaml
31+
32+
build-agent-manual:
33+
extends: .build-agent-tpl
34+
# We don't want to require the manual build job for regular pipelines.
35+
allow_failure: true
36+
rules:
37+
# By default we test with Agent's main branch.
38+
# From a release branch we want to use the same release branch in the agent repo.
39+
- if: $CI_COMMIT_BRANCH =~ "/^7.\d+.x$/"
40+
when: manual
41+
variables:
42+
_AGENT_BRANCH: ${CI_COMMIT_BRANCH}
43+
- when: manual

.gitlab/validate-agent-build/Dockerfile

Lines changed: 0 additions & 14 deletions
This file was deleted.

.gitlab/validate-agent-build/trigger_agent_build.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

.gitlab/validate-agent-build/validate_agent_build.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)