Conda activate not persistent in command

Our workflow has a number of jobs that depends on conda, so I thought to pull conda related items into a command however, activating the environment doesn’t persist into the actual job itself. For example

commands: 
conda_stuff:
    description: "setup and activate conda environment"
    steps:
      - run:
          command: |
            ...
            conda activate my_env

The job would be:

my_job:
    ...
    steps:
      ...
      - conda_stuff:
      - run:
          command: |
            conda env list

and the output would be:

# conda environments:
#
base                  *  /home/circleci/miniconda
my_env            /home/circleci/miniconda/envs/my_env

where base is activated.
Is there something I’m not understanding about how commands work?

Hi @SLinAppliedBiomath and welcome to our developer’s forum!

To recap, you have commands that each depend on a conda environment, but the environment is not persisted between run steps. Is that correct?

Each run step actually runs in its own subshell. So the environment that you activated in one run step will not be activated in the next. As such, you may need to run “conda activate my_env” in each run command.

Can you try that and see if you are able to use your conda environment that way?

Thank you!