From f6968f3091a0ccc2b5730b8daf0c5b749d55659f Mon Sep 17 00:00:00 2001
From: Alex Szabo <alex.szabo@elastic.co>
Date: Mon, 17 Jun 2024 10:42:47 +0200
Subject: [PATCH] [CI] Prevent duplicate serverless image build (#186164)

## Summary
Only adds build_project.yml if there's not already a deploy_project.yml
added through labels

## Context
Based on the labeling logic, if we had `ci:build-serverless-image` and
`ci:project-deploy-*`, the steps for building the docker image would be
added twice.

See: https://elastic.slack.com/archives/C0D8P2XK5/p1718268306523329
---
 .buildkite/scripts/pipelines/pull_request/pipeline.ts | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/.buildkite/scripts/pipelines/pull_request/pipeline.ts b/.buildkite/scripts/pipelines/pull_request/pipeline.ts
index 02011690a13c3..38ae590f18e0b 100644
--- a/.buildkite/scripts/pipelines/pull_request/pipeline.ts
+++ b/.buildkite/scripts/pipelines/pull_request/pipeline.ts
@@ -145,15 +145,14 @@ const getPipeline = (filename: string, removeSteps = true) => {
       pipeline.push(getPipeline('.buildkite/pipelines/pull_request/fips.yml'));
     }
 
-    if (GITHUB_PR_LABELS.includes('ci:build-serverless-image')) {
-      pipeline.push(getPipeline('.buildkite/pipelines/pull_request/build_project.yml'));
-    }
     if (
       GITHUB_PR_LABELS.includes('ci:project-deploy-elasticsearch') ||
       GITHUB_PR_LABELS.includes('ci:project-deploy-observability') ||
       GITHUB_PR_LABELS.includes('ci:project-deploy-security')
     ) {
       pipeline.push(getPipeline('.buildkite/pipelines/pull_request/deploy_project.yml'));
+    } else if (GITHUB_PR_LABELS.includes('ci:build-serverless-image')) {
+      pipeline.push(getPipeline('.buildkite/pipelines/pull_request/build_project.yml'));
     }
 
     if (