Jenkins构建部署

插件

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.13</version>
                <configuration>
                    <imageName>${project.artifactId}</imageName>
                    <imageTags>${project.version}</imageTags>
                    <dockerDirectory>./</dockerDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

imageName: 构建的image名字,重要
imageTags: 标签

Dockerfile

FROM openjdk:8-jdk-alpine
VOLUME /temp
EXPOSE 8080 
ARG JAR_FILE=target/test-1.0-SNAPSHOT.jar
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]
  1. 8080: 暴漏接口
  2. target/test-1.0-SNAPSHOT.jar : 打包之后的jar位置,相对pom的路径

Jenkins maven build 参数

clean package docker:build

build之后的执行命令

docker stop test;
docker rm test;
docker images|grep -n '<none>'|awk '{print $3}'|tr "\n" " " | xargs docker rmi;
docker run -d -p 8080:8080 --name test test:latest
  1. test:镜像名
  2. 停止当前容器
  3. 删除旧的容器
  4. 运行最新的镜像,镜像叫 test, tag latest 容器叫 test
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章