Unable to run `conda activate` from Jenkins pipeline I'm running Conda 4.6.14 on Ubuntu 16.04. 

I thought about using virtual environments with Conda in my Jenkins pipelines that needed Ansible, by having all nodes use the same environment, ansible-env to run playbooks. While the process seems pretty straight forward, I'm unable to call conda activate ansible-env, because it results in the following error:

+ conda activate ansible-env

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

    $ conda init &lt;SHELL_NAME&gt;

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'.


Here is the code I'm using to activate...pretty basic

sh("conda activate ansible-env")
sh("ansible --version")
sh("conda deactivate")


I ran conda init --system on the build node as the Jenkins user and then rebooted. No change. 

I've spent a great deal of time trying to google a solution, but everything I've tried hasn't worked.

What I've attempted:


Tried running sh("conda init bash") in the pipeline.
Executing . /home/jenkins/miniconda3/profile.d/conda.sh from within the pipeline.
Made sure the bin directory for miniconda3 is set in $PATH.
Ran dpkg-configure dash to make sure /bin/bash is the default shell on the node.
Tried sourcing the /home/jenkins/.bashrc file
Calling the conda executable via the absolute path. 
Tried using source ansible-env or activate ansible-env without conda.


I'm pretty sure the issue has to do with the following lines added to ~/.bashrc of the jenkins user after running conda init --system, but still not being accessible from that same user when a job is running. Unfortunately, I've hit a wall and not sure where to go from here. 

NOTE: Please don't suggest switching to VirtuanEnv unless there's a specific reason Conda won't work with Jenkins. I'm aware of that route, but went with conda for...reasons.
What we do is download and install miniconda in the first step in our (declarative) pipeline and create the environment(s) from a yaml file.

sh '''#!/usr/bin/env bash
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -nv -O miniconda.sh
bash miniconda.sh -b -p $WORKSPACE/miniconda
conda config --set always_yes yes --set changeps1 no
conda update -q conda

conda env create -f envs/ansible-env.yaml
'''


In each step we start the conda environment like so:

sh '''#!/usr/bin/env bash
source $WORKSPACE/miniconda/etc/profile.d/conda.sh
conda activate miniconda/envs/ansible-env/

# do stuff
'''