【问题标题】:Cache dependencies between GitLab CI build stages缓存 GitLab CI 构建阶段之间的依赖关系
【发布时间】:2019-04-26 16:58:28
【问题描述】:

我有以下 GitLab yml 文件,我分阶段编写它,假设每个阶段都会保留依赖项,但似乎并非如此!

# This file is a template, and might need editing before it works on your project.
# Official Java image. Look for the different tagged releases at
# https://hub.docker.com/r/library/java/tags/ . A Java image is not required
# but an image with a JVM speeds up the build a bit.
image: java:8

variables:
  FILE_TARGET_PATH: $FILE_TARGET_PATH

stages:
  - test
  - run

cache:
  key: "$CI_BUILD_REF_NAME" # contains either the branch or the tag, so it's caching per branch
  untracked: true
  paths:
    - "sbt-cache/.ivy.cache"
    - "sbt-cache/.boot"
    - "sbt-cache/.sbtboot"
    - "sbt-cache/target"

before_script:
  # Enable the usage of sources over https
  - apt-get update -yqq
  - apt-get install apt-transport-https -yqq
  # Add keyserver for SBT
  - echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
  - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
  # Install SBT
  - apt-get update -yqq
  - apt-get install sbt -yqq

Run unit Tests:
  stage: test
  tags:
    - master
  script:
    # Execute your project's tests
    - sbt -Denv=test clean test

Run Pipeline:
  stage: run
  tags:
    - master
  script:
    # Execute the pipeline
    - sbt -Denv=test run

如何在这个多阶段设置中缓存依赖项?我的机器上有一个运行管道的本地运行器。人工制品会对我有帮助吗?

【问题讨论】:

    标签: docker continuous-integration sbt gitlab


    【解决方案1】:

    如果您使用比 1.0.4 更新的 sbt 版本,缓存将无法为您工作,因为编译器将始终使所有文件无效。 此编译器问题已在此处报告:https://github.com/sbt/sbt/issues/4168

    我的建议是将 CI 的 sbt 版本降级到 1.0.4。如果这没有帮助,您还可以通过添加build.sbt 来检查缓存失效的原因:

    // Debug incremental zinc compiler
    logLevel := Level.Debug
    incOptions := incOptions.value.withApiDebug(true).withRelationsDebug(true)
    

    我在 Bitbucket Pipelines CI 上遇到了同样的问题,并成功地使其工作here

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 2016-12-16
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 2021-10-29
      • 2016-01-29
      相关资源
      最近更新 更多