'Run gitlab CI pipeline stage ONLY on clone of repo (or when a template was the source)?

I have a use case where I have a template project set up that I then use as a base for new microservices. While this works in building some basic stuff, such as base files, ci/cd pipeline, etc, it's still the template. I'm going through all the ci/cd variables now to check, but wanted to see if anyone else had this use case come up. Basically, I want to know if there's something like a "first run on repo creation" trigger that can run as soon as the repo is cloned from the template, but then never run again. This stage would modify some of the files in the repo to change names of things like the service, etc.

Is there any way to currently do this? The only other way I can think of doing it would be to have another project that uses the api or something to get the new repo name then check in the modified files.

Thanks!



Solution 1:[1]

You could use a rule that checks for a specific commit message crafted to be the message at the HEAD of the template project. Optionally, you can also check if the project ID is not the project ID of the template project (to avoid the job running in the template project itself).

rules:
  - if: '$CI_COMMIT_MESSAGE == "something very specific" && CI_PROJECT_ID != "1234"'

When a new project is created, the rule will evaluate true, but future commits that users make won't (or at least shouldn't, under normal circumstances) match the rule.

Though, to hook into project creation, using a system hook (for self-managed instances) might be a better option.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sytech