Gitlab-ci runner : how to perform operations before cloning the repository
Asked Answered
S

2

8

I wonder if it is possible to perform some operations before the repository is cloned. Indeed, as far as I know, gitlab-ci runner first action is to clone the repository to be built before any script can execute.

My problem:

  • To build my project (let's call it my plugin) I need to clone another specific repository, let's call it workspace, and then I need to perform some operations to configure this workspace (using cmake).
  • Once done, I need to put my project into a specific subfolder of the workspace, for instance in workspace folder/plugins/my plugin.
  • Then I just have to configure my plugin (using cmake) and build/test (using different make commands).

The intuitive way to do that would be to be able to perform early operations before my plugin is cloned by the runner. For instance something like:

  • cd builds/namespace/my plugin
  • git clone "git address of workspace"
  • cd workspace && cmake . -D"some definitions"
  • cd plugins

=> from here the clone / build / test can proceed as usual.

I know there is the before_script action, but it is performed after clone.

I also see that there is the pre_clone_script option in the [[runner]] section of the global config.toml file of a runner and I wonder if I can use it for this. Unfortunately, it would imply that all projects will run this script what is certainly not a good idea...

Well If anyone has a suggestion, or better a nice solution to this problem, I would greatly appreciate !

Spancel answered 13/10, 2016 at 20:40 Comment(2)
Well finally I managed the build differently.Spancel
Sure wish you shared how you built it differently for anybody in the same situation.Salesgirl
R
7

Since Gitlab 16 the pre_clone_script feature is deprecated in favor of pre_get_sources_script hook.

See https://about.gitlab.com/blog/2023/03/27/changes-to-the-preclonescript/ and https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section

The documentation says:

pre_clone_script DEPRECATED - use pre_get_sources_script instead.

pre_get_sources_script Commands to be executed on the runner before updating the Git repository and updating submodules. Use it to adjust the Git client configuration first, for example.

Reverso answered 8/9, 2023 at 9:37 Comment(0)
P
2

I know the question is old, but right now https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section mentions pre_clone_script but that requires modifying gitlab configuration

Paulenepauletta answered 2/11, 2021 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.