Fail to active conda in Azure DevOps pipeline

SLN

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

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

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

Merlin Liang - MSFT

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

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

In addition, please do not split the Add PATH, create environment and active the environment into different jobs.

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.

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 can only share files and pass variables between jobs. It can not keep the VM continued in next job.

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.

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Secret Pipeline Parameter in Azure Devops

分類Dev

Build pipeline for service fabric app on Azure devops

分類Dev

Azure DevOps release pipeline with git-flow

分類Dev

Include local dll in Azure DevOps pipeline

分類Dev

How to use previous Azure DevOps yaml pipeline name in triggered pipeline?

分類Dev

Azure DevOps Build Pipeline - A failed build still gets deployed to Azure

分類Dev

How to write a secret to azure key vault from Azure DevOps pipeline?

分類Dev

Azure devops pipeline get work items between builds

分類Dev

Azure DevOps Release Pipelines - Using Powershell with Pipeline variables inside brackets

分類Dev

Unable to print the variable right after set it in Azure devops pipeline

分類Dev

Migrate VS2017 Azure DevOps pipeline to VS2019

分類Dev

Azure Devops Pipeline trigger ignore paths when a tag is triggered

分類Dev

Azure Devops Build Pipeline for solution with multiple project types

分類Dev

Release pipeline to Prod is just queued, not starting to deploy- devops Azure

分類Dev

passing pipeline variable as argument into Powershell build step not working in Azure DevOps

分類Dev

How do you delay and schedule a stage to only run the latest build in an Azure Devops yaml pipeline?

分類Dev

Azure DevOps PipelineのMavenビルドエラー

分類Dev

Share PowerShell variable between two tasks of the job agent in Release pipeline in Azure DevOps

分類Dev

How to fix: In Azure Devops connection string is null despite setting Variable in the build Pipeline

分類Dev

Pass file content as build argument in azure devops pipeline docker build task

分類Dev

How can I exclude changes to the pipeline yaml file to trigger a build i azure devops?

分類Dev

How to add Approval before Slot Swap task in Release pipeline on Azure DevOps

分類Dev

Azure DevOps Pipeline Azure BlobStorageアップロードファイル403Forbidden Exception

分類Dev

In Azure Devops, how can i use pipeline variables in a "Azure CLI task v.2" running shell script?

分類Dev

Scripted Jenkins pipeline: continue on fail

分類Dev

Conda install r-topicmodels package fail

分類Dev

Azure DevOps Pipelineの定義を継承することは可能ですか?

分類Dev

Azure DevOps Multi Stage Pipeline Error: No package found with specified pattern: /home/vsts/work/1/s/**/*.zip - How do I fix?

分類Dev

azure devops variable group

Related 関連記事

  1. 1

    Secret Pipeline Parameter in Azure Devops

  2. 2

    Build pipeline for service fabric app on Azure devops

  3. 3

    Azure DevOps release pipeline with git-flow

  4. 4

    Include local dll in Azure DevOps pipeline

  5. 5

    How to use previous Azure DevOps yaml pipeline name in triggered pipeline?

  6. 6

    Azure DevOps Build Pipeline - A failed build still gets deployed to Azure

  7. 7

    How to write a secret to azure key vault from Azure DevOps pipeline?

  8. 8

    Azure devops pipeline get work items between builds

  9. 9

    Azure DevOps Release Pipelines - Using Powershell with Pipeline variables inside brackets

  10. 10

    Unable to print the variable right after set it in Azure devops pipeline

  11. 11

    Migrate VS2017 Azure DevOps pipeline to VS2019

  12. 12

    Azure Devops Pipeline trigger ignore paths when a tag is triggered

  13. 13

    Azure Devops Build Pipeline for solution with multiple project types

  14. 14

    Release pipeline to Prod is just queued, not starting to deploy- devops Azure

  15. 15

    passing pipeline variable as argument into Powershell build step not working in Azure DevOps

  16. 16

    How do you delay and schedule a stage to only run the latest build in an Azure Devops yaml pipeline?

  17. 17

    Azure DevOps PipelineのMavenビルドエラー

  18. 18

    Share PowerShell variable between two tasks of the job agent in Release pipeline in Azure DevOps

  19. 19

    How to fix: In Azure Devops connection string is null despite setting Variable in the build Pipeline

  20. 20

    Pass file content as build argument in azure devops pipeline docker build task

  21. 21

    How can I exclude changes to the pipeline yaml file to trigger a build i azure devops?

  22. 22

    How to add Approval before Slot Swap task in Release pipeline on Azure DevOps

  23. 23

    Azure DevOps Pipeline Azure BlobStorageアップロードファイル403Forbidden Exception

  24. 24

    In Azure Devops, how can i use pipeline variables in a "Azure CLI task v.2" running shell script?

  25. 25

    Scripted Jenkins pipeline: continue on fail

  26. 26

    Conda install r-topicmodels package fail

  27. 27

    Azure DevOps Pipelineの定義を継承することは可能ですか?

  28. 28

    Azure DevOps Multi Stage Pipeline Error: No package found with specified pattern: /home/vsts/work/1/s/**/*.zip - How do I fix?

  29. 29

    azure devops variable group

ホットタグ

アーカイブ