我是Jenkins-Groovy的新手,在使用Jenkins-Pipeline设置一些环境变量之前,我尝试在现有的Docker-Container中运行命令。
现在使用的bash-script (所以只需从命令行执行它)看起来就像这样,并且工作正常:
export LIB_ROOT=/usr/local/LIBS
export TMP_MAC_ADDRESS=b5:17:a3:28:55:ea
sudo docker run --rm -i -v "$LIB_ROOT":/usr/local/LIBS/from-host -v /home/sbuild/Dockerfiles/Sfiles/mnt:/home/sbuild/mount --mac-address="$TMP_MAC_ADDRESS" -t sbuild:current然后,我想在Docker-Container中构建一些源代码(挂载),使用如下代码:
python3 batchCompile.sh ../mount/src.zip 现在,我正试着在我的Jenkins中这样写它:
node ('linux-slave') {
withEnv(['PATH=/usr/local/LIBS:/usr/local/MATLAB/from-host -v /home/sbuild/Dockerfiles/Sfiles/mnt:/home/sbuild/mount --mac-address=b5:17:a3:28:55:ea']) {
docker.image('sbuild').inside {
sh 'echo $PATH'
sh 'mvn --version'
}
}
sh 'echo $PATH'
}然而,这只是失败了,并显示了一个不透明的消息:
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 71: Expected a symbol @ line 71, column 25.
docker.image('sbuild:current').inside {
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)我找不出哪里出了问题。所以我只是想进入码头看看我能从那里做些什么。在这个小脚本中,我做了一些实验:
script{
docker.image('sbuild:current').inside{
sh 'touch asdf'
sh 'cd /home/sbuild/'
sh 'pwd'
}然而,在默认情况下,我只是在Jeninks-文件夹中工作,并且这些命令都不会在Docker中实际调用。此外,容器似乎在任何时候都不会运行。
如何编写代码来启动我配置的Docker并在其中使用命令?
外面有一些关于创建新Docker容器的文档,但我很难弄清楚如何理解该错误消息以及如何正确调试。
编辑1: Dockerfile:
FROM labs:R2018
# Avoid interaction
ENV DEBIAN_FRONTEND noninteractive
# Set user to root
USER root
# =========== Basic Configuration ======================================================
# Update the system
#RUN apt-get -y update \
# && apt-get install -y sudo build-essential git python python-dev \
# python-setuptools make g++ cmake gfortran ipython swig ant python-numpy \
# python-scipy python-matplotlib cython python-lxml python-nose python-jpype \
# libboost-dev jcc git subversion wget zlib1g-dev pkg-config clang
# Install system libs
# RUN apt-get install sudo
# ========== Install pip for managing python packages ==================================
RUN apt-get install -y python-pip python-lxml && pip install cython
# Install simulix dependencies
RUN apt-get install -y git
RUN apt-get install --assume-yes python
RUN apt-get install --assume-yes cmake
RUN apt-get install --assume-yes mingw-w64
# Add User
#RUN adduser --disabled-password --gecos '' docker
#RUN adduser docker sudo
#RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER build
# Install simulix
WORKDIR /home/sbuild
RUN git clone https://github.com/***.git
RUN mkdir mount
WORKDIR /home/sbuild/Sfiles
RUN pip install -r requirements.txt发布于 2018-12-06 22:44:13
当我在Jenkins Pipeline中使用Docker时,我只使用sh步骤:
try {
stage('Start Docker') {
sh 'docker-compose up'
}
stage('Build project') {
sh 'docker-compose exec my_service make:build
}
} catch (Error e)
// Maybe do something
} finally {
sh 'docker-compose stop'
}您希望用try/catch/finally块围绕您的阶段,以便在失败的情况下始终停止docker容器。
https://stackoverflow.com/questions/53652567
复制相似问题