如何强制GitLab在开始一个新的管道之前运行一个完整的管道?

dgtucam1  于 2022-12-25  发布在  Git
关注(0)|答案(2)|浏览(132)

我有一个运行者与我的项目相关联,以避免并发构建。GitLab在开始一个新的之前处理整个管道?
concurrent设置为= 1(运行程序的配置文件)

before_script:
  - echo %CI_COMMIT_SHA%
  - echo %CI_PROJECT_DIR%

stages:
  - createPBLs
  - build
  - package

create PBLs:
  stage: createPBLs
  script: 
    - md "C:\HierBauen\%CI_COMMIT_SHA%\"
    - xcopy /y /s "C:/Bauen" "C:/HierBauen/%CI_COMMIT_SHA%"
    - xcopy /y /s "%CI_PROJECT_DIR%" "C:\HierBauen\%CI_COMMIT_SHA%"
    - cd "C:\HierBauen\%CI_COMMIT_SHA%"
    - ./run_orcascript.cmd
  only:
  - tags
  - master

build:
  stage: build
  script:
  - cd "C:\HierBauen\%CI_COMMIT_SHA%"
  - ./run_pbc.cmd
  only:
  - tags
  except:
  - master

build_master:
  stage: build
  script:
  - cd "C:\HierBauen\%CI_COMMIT_SHA%"
  - ./run_pbcm.cmd
  only:
  - master

package:
  stage: package
  script:
  - cd "C:\HierBauen\%CI_COMMIT_SHA%"
  - ./cpfiles.cmd
  artifacts:
    expire_in: 1 week
    paths:
      - GitLab-Build
    name: "%CI_COMMIT_REF_NAME%"
  only:
  - tags
  - master

不幸的是,较早启动的管道被新启动的管道所干扰。因此,构建在最后有缺陷...

编辑新配置文件:

before_script:
  - echo %CI_BUILD_REF%
  - echo %CI_PROJECT_DIR%
  - xcopy /y /s "C:/Bauen" "%CI_PROJECT_DIR%"

stages:
  - createPBLs
  - build
  - package

create PBLs:
  stage: createPBLs
  script: 
    - ./run_orcascript.cmd
  only:
  - tags
  - master

build:
  stage: build
  script:
  - ./run_pbc.cmd
  only:
  - tags
  except:
  - master

build_master:
  stage: build
  script:
  - ./run_pbcm.cmd


  only:
  - master

package:
  stage: package
  script:
  - ./cpfiles.cmd
  artifacts:
    expire_in: 1 week
    name: "%CI_COMMIT_REF_NAME%"
    paths:
      - GitLab-Build
  only:
  - tags
  - master
8iwquhpp

8iwquhpp1#

目前还没有这样的方法,目前在GitLab上有一个open issue
你可以在gitlab-runner的config.toml文件中添加limit = 1,这样gitlab-runner一次只能接受一个作业。
我看到您没有在阶段之间传递工件,但是如果您的build阶段依赖于createPBLs阶段中的任何内容,您可以使用工件和依赖项的组合在阶段之间传递数据。
例如:

before_script:
  - echo %CI_COMMIT_SHA%
  - echo %CI_PROJECT_DIR%

stages:
  - createPBLs
  - build
  - package

create PBLs:
  stage: createPBLs
  script: 
    - md "C:\HierBauen\%CI_COMMIT_SHA%\"
    - xcopy /y /s "C:/Bauen" "C:/HierBauen/%CI_COMMIT_SHA%"
    - xcopy /y /s "%CI_PROJECT_DIR%" "C:\HierBauen\%CI_COMMIT_SHA%"
    - cd "C:\HierBauen\%CI_COMMIT_SHA%"
    - ./run_orcascript.cmd
  artifacts:
    name: createPBLS_%CI_COMMIT_SHA%
    untracked: true
    expire_in: 1 day
  only:
  - tags
  - master

build:
  stage: build
  script:
  - cd "C:\HierBauen\%CI_COMMIT_SHA%"
  - ./run_pbc.cmd
  dependencies:
  - createPBLs
  artifacts:
    name: build_%CI_COMMIT_SHA%
    untracked: true
    expire_in: 1 day
  only:
  - tags
  except:
  - master

build_master:
  stage: build
  script:
  - cd "C:\HierBauen\%CI_COMMIT_SHA%"
  - ./run_pbcm.cmd
  dependencies:
  - createPBLs
  artifacts:
    name: build_%CI_COMMIT_SHA%
    untracked: true
    expire_in: 1 day
  only:
  - master

package:
  stage: package
  script:
  - cd "C:\HierBauen\%CI_COMMIT_SHA%"
  - ./cpfiles.cmd
  dependencies:
  - build_master
  artifacts:
    expire_in: 1 week
    paths:
      - GitLab-Build
    name: "%CI_COMMIT_REF_NAME%"
  only:
  - tags
  - master
wbrvyc0a

wbrvyc0a2#

使用resource_group功能,它提供了一种方法来分组需要相同互斥体 Package 的作业。开箱即用,resource_group不提供这种流水线级互斥(防止并发),但是,使用进程模式选项,特别是将其设置为“最旧的优先”,可以提供。
要更改资源组的进程模式,必须使用API并通过指定process_mode发送编辑现有资源组的请求:

unordered
oldest_first
newest_first

此处还提到:https://stackoverflow.com/a/74286510/532621

相关问题