我试图在我的Jenkinsfile中激活一个conda环境,该环境是从Dockerbuild创建的,但是我不知道如何在我的Jenkinsfile的shell脚本中激活该环境。
但是这行. /opt/conda/envs/myapp-env/bin/activate
无法在我的Jenkinsfile中激活
Dockerfile
FROM continuumio/miniconda3:latest
WORKDIR /tmp/app
COPY environment.yml environment.yml
#missing dependencies
RUN conda config --add channels conda-forge \
&& conda env create -n myapp-env -f environment.yml \
&& rm -rf /opt/conda/pkgs/*
ENV PATH /opt/conda/envs/myapp-env/bin:$PATH
RUN echo $PATH
RUN conda env list
Jenkinsfile :
try {
stage('Activate environment & Unit Test') {
buildImage.inside {
sh '''
echo $PATH
echo $HOME
. /opt/conda/envs/myapp-env/bin/activate && python -m pytest tests --cov ./server --cov-report term-missing --cov-report xml --junitxml=build/results.xml
'''
}
}
echo $ PATH和$ HOME的结果:
Running shell script
+ echo /opt/conda/envs/dfog-app/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/opt/conda/envs/myapp-env/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ echo /
最佳答案
在您的Dockerfile中,无需执行以下操作:
ENV PATH /opt/conda/envs/myapp-env/bin:$PATH
在您的Jenkinsfile中,执行以下操作:
source /opt/conda/etc/profile.d/conda.sh
conda activate myapp-env
python -m pytest tests --cov ./server --cov-report term-missing --cov-report xml --junitxml=build/results.xml
关于python-3.x - 从Jenkinsfile中的Docker镜像激活conda环境,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53111700/