4

We are using GitlabHQ and Gitlab-CI in our infrastructure. Having such continuous integration set we are willing to customize the build logic in CI.

Right now on new commit GitlabHQ triggers a hook to CI, which tells gitlab-ci-runner to run a build or test.

Runner has a hardcoded logic (at least not customizable in web UI) and before running user-defined scripts issues these commands:

cd $HOMEDIR/gitlab-ci-runner/tmp/builds && git clone git@$GITLABSERVER:root/test1.git project-1 && cd project-1 && git checkout $COMMIT

cd $HOMEDIR/gitlab-ci-runner/tmp/builds/project-1 && git reset --hard && git checkout $COMMIT

and then user-defined scripts go

What do I want:

  • customize options passed to git
  • run some user-defined scripts before commands above are issued (in my case I want to start a Virtual Machine kept on runner in order to get a clean env for tests)

The questions is: Has anyone hit the similar situation? Is there a nice way to workaround the absence of needed options?

Right now I am using a very dirty hack: replaced git binary with bash script named 'git', which catches options passed to git and runs it inside virtual machine, but that does not seem to be a nice way IMO.

Alexander Gladysh
  • 2,343
  • 7
  • 30
  • 47

1 Answers1

1

Not sure if it's what you want, but you can disable pulling code from git completely by setting GIT_STRATEGY to none:

variables:
  GIT_STRATEGY: none

https://docs.gitlab.com/ce/ci/yaml/#git-strategy

To run commands before job execution, you can use "before_script" directive

before_script is used to define the command that should be run before all jobs, including deploy jobs, but after the restoration of artifacts. This can be an array or a multi-line string.

https://docs.gitlab.com/ce/ci/yaml/#before_script-and-after_script

Mr.Pisos
  • 11
  • 1