Halo
发布于 2023-02-27 / 77 阅读 / 0 评论 / 0 点赞

gitlab ci compose with submodules

configure the .gitmodules file in your project root dir

[submodule "backtest_task"]
	path = project_name
	url = git@ip_or_host:group_name/project_name.git

add ssh private key for accessing submodules repo in your gitlab-runner machine

mkdir -p ~/.ssh
cd ~/.ssh
echo "${SSH_PRIVATE_KEY}" > id_rsa
chmod 600 id_rsa
ssh-keyscan -t rsa  ip_or_host -p port >> known_hosts

configure the .gitlab-ci.yml file in your project root dir

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  variables: 
    GIT_SUBMODULE_STRATEGY: recursive
    GIT_SUBMODULE_UPDATE_FLAGS: --jobs 4
  script:
    - mkdir build
    - cd build
    - cmake ..
    - make

unit-test-job:   # This job runs in the test stage.
  stage: test    # It only starts when the job in the build stage completes successfully.
  script:
    - echo "Code coverage is 90%"

deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  environment: production
  script:
    - cp build/backtest_factor /root/data

评论