如何通过 docker 启动我的 jenkins-cli?

How do i launch my jenkins-cli through docker?

我已经创建了安装 java、jenkins、jenkins-cli 的 docker 图像。现在我需要通过 jenkins-cli 传递一些参数,所以我需要启动 jenkins-cli。我该怎么做?我不知道它是如何启动的。

这是我的脚本

    FROM ubuntu:14.04
RUN apt update; \
  apt upgrade -y; \
  apt install -y default-jdk curl wget git maven nano unzip; \
  apt-get clean
ENV JAVA_HOME /usr
ENV PATH $JAVA_HOME/bin:$PATH

RUN apt-get autoclean $$ apt-get clear cache
RUN apt-get -yqq update 
RUN apt-get -yqq --no-install-recommends install git bzip2 curl unzip
RUN apt-get update

# copy jenkins war file to the container
ADD http://mirrors.jenkins.io/war-stable/2.107.1/jenkins.war /opt/jenkins.war
RUN chmod 644 /opt/jenkins.war
ENV JENKINS_HOME /jenkins

# configure the container to run jenkins, mapping container port 8080 to that host port
ENTRYPOINT ["java", "-jar", "/opt/jenkins.war"]
EXPOSE 8080
RUN mkdir /jenkins/
RUN echo 2.107.1 > /jenkins/jenkins.install.UpgradeWizard.state
RUN echo 2.107.1 > /jenkins/jenkins.install.InstallUtil.lastExecVersion

#jenkin-cli installation
RUN cd /tmp && curl --insecure -OL http://192.168.99.100:8080/jnlpJars/jenkins-cli.jar 
ADD /tmp/jenkins-cli.jar /opt/jenkins/jenkins-cli.jar
RUN chmod 644 /opt/jenkins-cli.jar
WORKDIR /opt/jenkins
ENTRYPOINT ["java", "-jar", "jenkins-cli.jar", "-noCertificateCheck", "-noKeyAuth"]
CMD ["--help"]

这是错误:

Step 19/24 : RUN cd /tmp && curl --insecure -OL http://192.168.99.100:8080/jnlpJars/jenkins-cli.jar
 ---> Using cache
 ---> 9a6210009f84
Step 20/24 : ADD jenkins-cli.jar /opt/jenkins/jenkins-cli.jar
ADD failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder945232568/jenkins-cli.jar: no such file or directory[1] 

这个错误也会导致我进行其他构建,如果我能找到最佳解决方案,我就能解决所有其他问题。 第二个问题是,我针对当前问题编写的脚本是否正确?我该如何修改?

谁能帮我解决这个问题..? 提前谢谢你

您忘记创建 /opt/jenkins 文件夹

改变

添加http://mirrors.jenkins.io/war-stable/2.107.1/jenkins.war/opt/jenkins.war

运行 mkdir /opt/jenkins 添加 http://mirrors.jenkins.io/war-stable/2.107.1/jenkins.war /opt/jenkins/jenkins.war

鉴于您的 cli 工具可以从您的容器中使用一个简单的命令,例如 cli-tool_command 这应该可以工作:

docker run --rm -it {container_image_name} {cli_tool_command} {cli_tool_args}