如何在多个 gitlab 运行器配置中的作业之间共享“构建存储库目录”?

问题描述 投票:0回答:1

我正在使用 gitlab runner 来部署应用程序 -共享 gitlab runner 且并发数为 4

/etc/gitlab-runner/config.toml
        concurrent = 4
        check_interval = 0
        executor = shell

所有作业都在不同的阶段运行。

.gitlab-ci.yml

stages:
  - build-prod-stage
  - deploy-prod-stage

BUILD_PROD_JOB:
  stage: build-prod-stage
  variables:    
    GIT_CLEAN_FLAGS: none      
  script:
    - xxxxxx
    - xxxxx

DEPLOY_PROD_JOB:
  variables:
    GIT_CLEAN_FLAGS: none 
  stage: deploy-prod-stage
  script: 
    - xxxxxx
    - xxxxxx*

大多数情况下,BUILD_PROD_JOB 和 DEPLOY_PROD_JOB 在同一构建目录中运行。 但是,有时他们彼此使用不同的目录

gitlab-runner 日志

构建_产品_作业 正在将 git 深度设置为 50 来获取更改... 在 /xxxx/gitlab-runner/builds/(gitlab-runner name)/1/(respository name)/.git/ 中初始化空 Git 存储库 ......

部署_产品_作业 正在将 git 深度设置为 50 来获取更改... 在 /xxxx/gitlab-runner/builds/(gitlab-runner name)/0/(respository name)/.git/ 中初始化空 Git 存储库 ....

我猜到为什么会发生这种事了。

  • BUILD_PROD_JOB 在其他作业运行时开始运行。所以,CI_CONCURRENT_ID 是 1
  • DEPLOY_PROD_JOB 在其他作业完成后开始运行,因此 CI_CONCURRENT_ID 为 0

在这种情况下,我可以强制“DEPLO_PROD_JOB”在“BUILD_PROD_JOB”的同一个 build_dir 中运行吗?

  • BUILD_PRODJOB --> /xxxx/gitlab-runner/builds/(gitlab-runner 名称)/1/(存储库名称)/.git/
  • DEPLOY_PRODJOB --> /xxxx/gitlab-runner/builds/(gitlab-runner 名称)/1/(存储库名称)/.git/

在这种情况下,我可以强制“DEPLO_PROD_JOB”在“BUILD_PROD_JOB”的同一个 build_dir 中运行吗?

gitlab gitlab-ci-runner
1个回答
0
投票

这看起来你们的工作相互依赖,例如。 G。

DEPLOY_PROD_JOB
需要在
BUILD_PROD_JOB
中创建的文件。您应该尝试使用
artifacts
关键字
将文件从一个作业传递到另一个作业,而不是强制 GitLab Runner 对作业使用相同的目录。这样,解决方案就独立于 GitLab Runner 的主机。

stages:
  - build-prod-stage
  - deploy-prod-stage 

BUILD_PROD_JOB:
  stage: build-prod-stage
  variables:
    GIT_CLEAN_FLAGS: none
  script:
    - xxxx
    - xxxx
  artifacts:
    paths:
      - myBuildFiles/*
  
  DEPLOY_PROD_JOB:
    stage: deploy-prod-stage
    variables:
      GIT_CLEAN_FLAGS: none
    script:
      - xxxx
      # "myBuildFiles/" is now available here
      - xxxx

请注意,顶级目录中的通配符,例如

artifacts:
  paths:
    - *

还将存档

.git
目录,这可能会导致奇怪的行为。

© www.soinside.com 2019 - 2024. All rights reserved.