0

There is a group that hosts 00_Parent_Project: the source project containing e.g. .gitlab-ci.yml template:

Group
   [project] 00_Parent_Project
      [repo] .gitlab-ci.yml

How, using GitLab API, can I clone the source project, so that the target projects already contain repository with .gitlab-ci.yml?:

Group
   [project] 00_Parent_Project
      [repo] .gitlab-ci.yml

   [project] 01_Child_Project
      [repo] .gitlab-ci.yml

   [project] 02_Child_Project
      [repo] .gitlab-ci.yml

I'm not sure if sharing the CI template between projects should be taken into consideration as the target projects will be created by a request coming from backend server.

What would be the most efficient way to achieve this?

AbreQueVoy
  • 1,748
  • 8
  • 31
  • 52

1 Answers1

0

One way to achieve this is sending a POST request to /api/v4/projects/ with the following headers:

Content-Type: application/json
Private-Token: <gitlab token>

and body like:

{
    "name": "01_New_Child_Project",
    "namespace_id": <ID of a Group>,
    "description": "Project description here",
    "import_url": "https://username:password@gitlab.example.com/my_group/00_parent_project.git"
}

Right after creating the new project, GitLab imports repository from the parent project. In my case, the whole parent project's repository can be used as a template for children projects, so no further actions are required.

In other cases, unnecessary files can be deleted via API: GitLab Repository files API describes such actions.

Another thing to be considered is refactoring code so that the import_url value isn't present in plain text: why it contains username and password!

AbreQueVoy
  • 1,748
  • 8
  • 31
  • 52