使用Shell Executor为CI-CD激活GitLab Config yml文件中的Conda环境



我想在我的Gitlab CI-CD进程中激活conda环境。我在一台与我的工作笔记本电脑不同的本地机器(UNIX(上用Shell Executitor注册了Gitlab runner(v13.10(我正试图通过我的repo中的环境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命令未找到

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

我提到了这里和这里发布的各种问题。此外,我还尝试将anaconda路径添加到环境路径变量的bash文件中。但我不确定我是否做得正确

我的问题是:

  1. 既然它在shell执行器上运行,而我已经有conda在运行,为什么它不能接收它呢。如何在GitLab配置文件中修复此问题
  2. 出于我的目的,我对docker图像的使用有限制,我想坚持使用Shell执行器

对我有用的方法是使用conda-docker映像,并执行命令conda init bashsource ~/.bashrcconda activate env_name。这将是.gitlab-ci.yml文件的内容:

image: continuumio/miniconda3
before_script:
- apt-get update
# install all required libraries using existing conda environment requirements file:
- conda env create -f env_name.yml
- conda init bash
- source ~/.bashrc
- conda activate env_name

pages:
stage: deploy
script:
# build and publish automated documentation with Sphinx:
- PYTHONPATH=. sphinx-build -b html . public
artifacts:
paths:
- public
only:
- master

最新更新