无法在Azure DevOps管道中激活conda [英] Fail to active conda in Azure DevOps pipeline

查看:82
本文介绍了无法在Azure DevOps管道中激活conda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在由conda构建的python项目上测试azure devops管道

Testing the azure devops pipeline on a python project build by conda

jobs:
  - job: pre_build_setup
    displayName: Pre Build Setup
    pool:
      vmImage: 'ubuntu-18.04'
    steps:
      - bash: echo "##vso[task.prependpath]$CONDA/bin"
        displayName: Add conda to PATH

  - job: build_environment
    displayName: Build Environment
    dependsOn: pre_build_setup
    steps:
      - script: conda env create --file environment.yml --name build_env
        displayName: Create Anaconda environment
      - script: conda env list
        displayName:  environment installation verification

  - job: unit_tests
    displayName: Unit Tests
    dependsOn: build_environment
    strategy:
      maxParallel: 2
    steps:
      - bash: conda activate build_env

最后一步-bash:conda activate build_env 对我失败,出现以下错误

The last step - bash: conda activate build_env fails on me with the following error

Script contents:
conda activate build_env
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/d5af1b5c-9135-4984-ab16-72b82c91c329.sh

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


##[error]Bash exited with code '1'.
Finishing: Bash

如何激活conda?似乎路径错误,因此无法找到conda.

How can I active conda? seems the path is wrong so that it is unable to find conda.

推荐答案

CommandNotFoundError:您的外壳尚未正确配置为使用"conda激活".

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

这里的问题是您的脚本在子外壳中运行,但是 conda 尚未在该子外壳中初始化.

Here the issue is your script is run in a sub-shell, but condahasn't been initialized in this sub-shell.

您需要将您的活动脚本更改为:

You need change your active script as:

steps:
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
        eval "$(conda shell.bash hook)"
        conda activate build_env
    displayName: Active


此外,请勿将添加路径创建环境激活环境分成不同的作业.

对于Azure devops管道,代理作业是管道运行过程的基本单元,每个代理作业都有自己独立的运行环境和工作逻辑.

For Azure devops pipeline, agent job is the basic unit of the pipeline running process and each agent job has its own independent running environment and work logic.

有关详细信息,您正在使用托管代理在此问题方案中应用脚本.

For more detailed, you were using Hosted agent to apply your scripts in this issue scenario.

有一个代理作业开始运行时,我们的池系统将分配虚拟机到该代理作业.而且,代理程序作业完成后,该VM将回收.当下一个代理作业开始运行时,将随机重新分配一个全新的VM.

While there's one agent job starts to run, our pool system will assign an VM to this agent job. And, this VM will be recycled back once the agent job finished. When next agent job start to run , a completely new VM will be randomly reassign.

dependsOn 只能共享文件并在作业之间传递变量.它无法使VM继续执行下一个作业.

dependsOn can only share files and pass variables between jobs. It can not keep the VM continued in next job.

我相信您应该能够猜出您将要遇到的问题.是的,即使您可以成功应用该 activate 脚本,也将继续面临另一个错误:找不到conda环境:build_env .这是因为此 activate 脚本使用的环境是全新的虚拟机,以前的 build_environment 作业使用的虚拟机已被回收.系统.

I believe you should be able to guess what problem you are going to encounter. Yes, even you can succeed to apply that activate script, you will continue face another error: Could not find conda environment: build_env. That's because the environment which is using by this activate script is a brand new vm, the VM that previous build_environment job used has been recycled by the system.

因此,请勿拆分创建环境并将其激活为2个代理作业:

So, do not split the create environment and activate into 2 agent jobs:

  - job: build_environment
    displayName: Build Environment
    dependsOn: pre_build_setup
    steps:
      - script: conda env create --file environment.yml --name build_env
        displayName: Create Anaconda environment
      - script: conda env list
        displayName:  environment installation verification
      - task: Bash@3
        inputs:
          targetType: 'inline'
          script: |
            eval "$(conda shell.bash hook)"
            conda activate build_env
        displayName: Active

这篇关于无法在Azure DevOps管道中激活conda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆