Jenkins-Docker-Tomcat-Java Rest 使用shell脚本构建项目示例
jenkins docker tomcat java restful shell    2017-07-19 21:50:48    772   

前提:jenkins是装在CentOS6.7中,同时,我的这台linux上面安装有docker


一、项目代码:

项目主要是jersey 1.x 版本的maven项目,重点在与我在项目中放置了tomcat,以及使用maven对tomcat进行解压,并将项目打包的文件放置到项目中,那么项目信息就不多写了,把maven配置信息重点写出来吧:

    <build>
        <finalName>testjersey</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <id>copy-package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>

                                <unzip dest="target/apache/">
                                    <fileset dir="${basedir}">
                                        <include name="apache-tomcat-7.0.68.zip" />
                                    </fileset>
                                </unzip>
                                <copy todir="target/apache/apache-tomcat-7.0.68/webapps/testjersey/">
                                    <fileset dir="${basedir}/target/testjersey/" />
                                </copy>
                                <zip destfile="target/apache-tomcat-7.0.68.zip">
                                    <zipfileset dir="target/apache/apache-tomcat-7.0.68/" excludes="**/*.sh" />
                                    <zipfileset dir="target/apache/apache-tomcat-7.0.68/" includes="**/*.sh" filemode="755" />
                                </zip>  
                                <copy todir="target/">
                                    <fileset file="${basedir}/Dockerfile" />
                                </copy>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>



然后项目根目录下存放Dockerfile文件

FROM isuper/java-oracle:jre_7
MAINTAINER liuyg<lyg210@msn.cn>
ADD target/apache /usr/local/

RUN set -x \
    && chmod 777 /usr/local/apache-tomcat-7.0.68/bin/*.sh \
    && rm /usr/local/apache-tomcat-7.0.68/bin/*.bat

ENV CATALINA_HOME /usr/local/apache-tomcat-7.0.68
ENV PATH $CATALINA_HOME/bin:$PATH
WORKDIR $CATALINA_HOME

EXPOSE 8080

CMD ["catalina.sh", "run"]


二、jenkins配置
 

jenkins安装插件之类的操作就不再描述了(在这里没有使用jenkins的docker插件)

 
其实打包就是基本的maven项目打包方式,加上执行脚本(Add post-build step -->Execute shell)

如下是执行的脚本,我去除了停止以前的包以及重启docker服务的操作
#!/bin/sh
id
set +e
docker build -t testjersey1 /var/lib/jenkins/jobs/testJersey1/workspace | tee /var/lib/jenkins/jobs/testjersey1/workspace/Docker_build_result.log
RESULT=$(cat /var/lib/jenkins/jobs/testJersey1/workspace/Docker_build_result.log | tail -n 1)


by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/



 

Pre: XWiki安装(war包方式)

Next: nginx证书填写路径报错:library:fopen:Unknown error:fopen


Table of content