【发布时间】:2021-06-22 23:31:40
【问题描述】:
我想在我的 Gitlab CI-CD 进程中激活 conda 环境。 我在不同于我的工作笔记本电脑的本地机器 (UNIX) 上使用 Shell Executor 注册了 Gitlab 运行器 (v13.10) 我正在尝试通过我的仓库中存在的环境 yml 文件来激活 conda 环境,但它失败并说找不到 conda 命令!
我编辑了 .gitlab-ci.yml 文件,如下所示:
stages:
- build
build stage:
stage: build
before_script:
- which python
- export PIP_CACHE_DIR="/opt/cache/pip"
- conda env create -f environment.yml
- source activate env_work
script:
- echo "Building"
- cd parent_dir
- python main.py new_studies/first_study
artifacts:
paths:
- out/
only:
- master
我面临的问题是它引发错误:CONDA Command NOT FOUND
Running with gitlab-runner 13.10.0 (5421146)
on rig ci runner gZzdceA
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on rig-machine...
Getting source from Git repository
00:04
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/gZzdceA/0/company/gg/product/repo/.git/
Checking out 883ga36 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ export PIP_CACHE_DIR="/opt/cache/pip"
$ conda env create -f environment.yml
bash: line 120: conda: command not found
Cleaning up file based variables
00:00
ERROR: Job failed: exit status 1
我提到了诸如here 和here 之类的各种问题。另外,我尝试将 anaconda 路径添加到环境路径变量的 bash 文件中。但我不确定我是否做得正确
我的问题是:
- 既然它在 shell 执行器上运行,而且我已经在运行 conda,为什么它无法获取它。如何在我的 GitLab 配置文件中解决此问题
- 我对 docker 镜像的使用有限制,我想坚持使用 Shell 执行器
【问题讨论】:
-
Conda 通常通过
.bashrc添加到 PATH 中(默认配置中包含来自conda init的代码)。可能需要让 shell 会话在登录模式下运行(-l标志)或手动添加一行来初始化 Conda(例如,. <path_to_anaconda>/etc/profile.d/conda.sh)。另请注意,conda activate env_work优于source activate env_work- 后一种语法是 Conda v4.6 之前的语法。
标签: python anaconda gitlab conda gitlab-ci-runner