【问题标题】:How to add Stack and GHC on GitLab's Continuous Integration?如何在 GitLab 的持续集成中添加 Stack 和 GHC?
【发布时间】:2021-04-17 23:01:53
【问题描述】:

我的 CI 找不到堆栈,我不知道为什么。我正在使用以下 .gitlab-ci.yml 文件为 Haskell Stack 项目设置 gitlab-CI。我是从this other question that claims it worked 那里拿到的。

image: haskell:8.6.5

cache:
  paths:
    - .stack
    - .stack-work
    - target

test:
  stage: test
  script:
    - ghc --version
    - stack --system-ghc build
    - stack test

但是它失败并报告(下面的完整输出):

bash: line 96: ghc: command not found
ERROR: Job failed: exit status 1

很明显,ghc 不见了,但我认为图像上出现了 haskell:8.6.5 不是吗?

我尝试了其他图片,例如image: fpco/stack-build:lts-11.15,但没有任何运气(报告bash: line 96: stack: command not found)。

我最好的猜测是我错过了确保ghcstack 在我使用的图像上的关键步骤,但我无法弄清楚它是什么。那么,我错过了什么?

编辑:完整的错误输出

Running with gitlab-runner 13.2.2 (a998cacd)
  on karson: Ubuntu 20.04 LTS Shared q_B8_V-j
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on karson...
Getting source from Git repository
00:01
Fetching changes with git depth set to 50...
Initialized empty Git repository in /var/lib/gitlab-runner/builds/q_B8_V-j/0/fromager/cheesecloth/MicroRAM/.git/
Created fresh repository.
Checking out 4d7e065d as 39-continuous-integration...
Skipping Git submodules setup
Restoring cache
00:00
Checking cache for default...
Runtime platform                                    arch=amd64 os=linux pid=4053876 revision=a998cacd version=13.2.2
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:00
$ ghc --version
bash: line 96: ghc: command not found
ERROR: Job failed: exit status 1

【问题讨论】:

  • 你能发布完整的输出日志吗?目前的猜测是它没有使用haskell:8.6.5 和其他一些默认图像,但应该在作业日志的顶部显示。
  • 添加了完整的输出。你可能是对的,似乎它没有加载 Haskell,但我不知道如何让它做到这一点。我虽然 image: haskell:8.6.5 是执行此操作的命令。

标签: haskell gitlab gitlab-ci ghc haskell-stack


【解决方案1】:

从输出日志中,您使用的是shell 执行程序而不是docker 执行程序,这就是image 标记在这里不起作用的原因。


要解决的选项是:

  • 如果您可以访问运行器的服务器,请将运行器重新安装为 docker 执行器 (https://docs.gitlab.com/runner/install/docker.html),并确保使用 tags 指定用于作业的运行器。 (您可能不一定需要重新安装运行器,只需将运行器安装在 shell 运行器旁边,但您需要确保正确使用 tags 来确定是否要使用 shell 运行器或 docker赛跑者)。

  • 作为 shell 手动运行 docker 命令(尽管这个不太理想)。


更新:为了确保您为工作选择正确的跑步者:

registering跑步者时,在第5步,您可以提供与跑步者相关的标签。如果您有足够的权限,您还可以在 GitLab UI 中更改标签:

gitlab.com -> group -> settings -> CI/CD -> runner settings

注意,运行器标签在 config.toml 文件中是不可更改的。

例如,您现在可以使用docker-internal 标记您的跑步者,然后仅在此跑步者上运行作业,请在您的 gitlab-ci.yml 文件中添加标记:-docker-internal

test:
  stage: test
  script:
    - ghc --version
    - stack --system-ghc build
    - stack test
  tags:
    - docker-internal

【讨论】:

  • 有道理,谢谢。我有几个共享的跑步者,其中一些有 docker。有没有办法挑选这些?
  • 是的,我已经用更多信息更新了答案。
  • 做到了。谢谢!
猜你喜欢
  • 2019-10-31
  • 2019-11-28
  • 2022-01-19
  • 2020-01-29
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
  • 1970-01-01
相关资源
最近更新 更多