简体   繁体   English

Dockerfile作为具有Maven设置的詹金斯奴隶

[英]Dockerfile as jenkins slave with maven settings

I am using the image jenkins/ssh-slave as base in my dockerfile. 我在我的dockerfile中使用映像jenkins / ssh-slave作为基础。 I would like to install a specific maven version and configure the settings. 我想安装特定的Maven版本并配置设置。 But it does not work, it is not picking the settings to download the artifactories from my nexus. 但这是行不通的,它不是从我的关系中选择设置来下载工件的。 Moreover, I dont know who to specify the maven version :( 而且,我不知道谁指定Maven版本:(

You can see my dockerfile below. 您可以在下面看到我的dockerfile。 I have tried to install Maven typing maven:3.5.6 but it says it cannot find that. 我试图安装键入maven:3.5.6的Maven,但它说找不到。 And also I copy my settings but maven does not go to my nexus to download the dependencies (the settings.xml works in local) 而且我也复制了我的设置,但是maven并没有去我的网站下载依赖项(settings.xml在本地工作)

FROM jenkins/ssh-slave

# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean   

# Install maven 
RUN apt-get install -y maven

COPY ./settings.xml /usr/share/maven/conf/settings.xml

Can anyone help? 有人可以帮忙吗? Thank you very much in advance. 提前非常感谢您。

As per your question, 根据您的问题,

I would like to install a specific maven version and configure the settings. 我想安装特定的Maven版本并配置设置。

I would suggest you to use Maven Wrapper ( mvnw ) instead of mvn command. 我建议您使用Maven Wrappermvnw )代替mvn命令。 This will give you flexibility to build an application without pre installing Maven in a vm or a system. 这将使您可以灵活地构建应用程序,而无需在vm或系统中预先安装Maven。 Since you are using Docker and somewhere you are using mvn clean install command, I would suggest you to use mvnw clean install. 由于您正在使用Docker,并且在某处使用mvn clean install命令,因此建议您使用mvnw clean install。

There is a difference between mvn clean install and mvnw clean install . mvn 全新 安装mvnw全新安装之间有区别。 If you want a specific version of maven, you can also set in maven-wrapper.properties file. 如果需要特定版本的Maven,也可以在maven-wrapper.properties文件中进行设置。

I provide below few links so that it will be useful for you. 我在下面提供一些链接,以便对您有用。

https://www.baeldung.com/maven-wrapper https://www.baeldung.com/maven-wrapper

What is the purpose of mvnw and mvnw.cmd files? mvnw和mvnw.cmd文件的目的是什么?

If want a very simple example on maven wrapper, refer below the github link. 如果要在Maven包装器上有一个非常简单的示例,请参阅下面的github链接。 https://github.com/debjava/maven-wrapper-example https://github.com/debjava/maven-wrapper-example

FROM jenkins/ssh-slave

# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean
RUN apt-get install -y curl 

ARG MAVEN_VERSION=3.6.2
ARG USER_HOME_DIR="/usr/jenkins"
ARG SHA=d941423d115cd021514bfd06c453658b1b3e39e6240969caf4315ab7119a77299713f14b620fb2571a264f8dff2473d8af3cb47b05acf0036fc2553199a5c1ee
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
  && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
  && echo "${SHA}  /tmp/apache-maven.tar.gz" | sha512sum -c - \
  && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
  && rm -f /tmp/apache-maven.tar.gz \
  && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"

RUN chown -R jenkins:jenkins /home/jenkins &&  chmod -R 777 /home/jenkins
COPY --chown=jenkins:jenkins ./settings.xml /home/jenkins/.m2/settings.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM