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 <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'.
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
oractivate ansible-env
withoutconda
.
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.