diff --git a/core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php b/core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php
index b9bdc34df0ac48df65094c5e7ad4f0af5da7bda1..f7127da07694b0d48257bc75c5e5664cec7eda58 100644
--- a/core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php
+++ b/core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php
@@ -270,6 +270,10 @@ protected function createTestProject(string $template): void {
     // Allow pre-release versions of dependencies.
     $this->runComposer('composer config minimum-stability dev', $template_dir);
 
+    // Allow any version of Drupal core as in test using a git clone on Gitlab
+    // core will be checked out at a specific commit hash.
+    $this->runComposer("composer require --no-update drupal/core:'*'", "composer/Metapackage/CoreRecommended");
+
     // Remove the packages.drupal.org entry (and any other custom repository)
     // from the template's repositories section. We have no reliable way of
     // knowing the repositories' names in advance, so we get that information