Skip to content

[CI][Backports] Avoid triggering all package tests on the first commit of a backport branch #18869

@mrodm

Description

@mrodm

Summary

When a new backport branch is created via the backport pipeline, a commit is pushed that updates CI infrastructure files (.buildkite/, .github/workflows/, go.mod, go.sum, magefile.go, etc.). This commit triggers a Buildkite build that ends up testing all packages in the repository, even though no package code has changed.

Testing all packages in this scenario is unnecessary: the packages are identical to the commit in main from which the branch was created, and those were already tested there.

Root cause

The function get_from_changeset() in .buildkite/scripts/common.sh#L626 falls back to origin/${BUILDKITE_BRANCH}^ when no previous successful build exists for the branch. The diff from that point to HEAD includes the CI infrastructure files committed by the backport script, which are not covered by the non_package_patterns exclusion list in is_pr_affected(), causing all packages to be marked as affected.

Suggested approaches

Option A — Reuse the existing get_previous_successful_commit signal

get_from_changeset() already calls get_previous_successful_commit() for backport-* branches (common.sh#L642-L649). When it returns "null", no successful build has ever run on that branch — for a freshly created backport branch this means it is the initial push.

The fix would change the fallback behaviour in that function:

if [[ "${previous_successful_commit}" == "null" ]]; then
    # First push of a new backport branch: only CI infrastructure files changed,
    # no package code was modified — skip package testing.
    from="${BUILDKITE_COMMIT}"  # same as $to → empty diff
fi

This is a minimal change that reuses already-computed data (Buildkite API call already in place).

Option B — Count commits since the branching point from main

commit_count=$(git rev-list --count "$(git merge-base origin/main HEAD)..HEAD")

If commit_count == 1, only the CI infrastructure commit was added on top of the main branching point, confirming this is the first push of the backport branch. This approach is independent of the Buildkite API and does not rely on build history being available.

Both options can be combined as a guard: branch name matches ^backport- and one of the above conditions is true.

Metadata

Metadata

Assignees

Labels

Team:EcosystemPackages Ecosystem team [elastic/ecosystem]

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions