Jenkins通过SSH将WAR部署到Tomcat?

时间:2016-07-18 04:59:08

标签: tomcat jenkins jenkins-plugins

Jenkins是否有一个插件可以通过SSH包装对Tomcat管理器的调用?

我的公司即将部署一些应用程序"在云端",我们似乎将使用Jenkins。问题是,我很不舒服地将Tomcat Manager打开到Internet。

或者,Jenkins是否可以在部署之前打开到目标服务器的VPN连接?

3 个答案:

答案 0 :(得分:1)

您可以使用Publish Over SSH Plugin

答案 1 :(得分:0)

可能你可以写一个Ansible脚本来完成这项工作并在Jenkins中使用它。

答案 2 :(得分:0)

为什么不为tomcat启用SSL并在其前面放置一个反向代理?

您server.xml中的连接器看起来像这样:

->

 <Connector  address="<localhost IP>" port="<port>" protocol="org.apache.coyote.http11.Http11NioProtocol"
            maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
            clientAuth="false" sslProtocol="TLS"
            ciphers="<Cipher1>,
                     <Cipher2>,
                     <Cipher3>" 
            keystoreFile="<keystore directory>"          
            keystorePass="<keystore password>"
            URIEncoding="UTF-8"
            connectionTimeout="120000"
            maxPostSize="-1"
            maxKeepAliveRequests="-1"
            />

要部署您的war文件,您可以在jenkins脚本中使用由ant执行的xml文件:

<project name="Deploy" default="deploy">
<path id="tomcat.class.path">
<fileset dir="<TomcatHome>/lib">
        <include name="**/*.jar"/>
    </fileset>
<pathelement location="<TomcatHome>/bin/bootstrap.jar"/>
<pathelement location="<TomcatHome>/bin/tomcat-juli.jar"/>
</path>
<target name="tomcat-start">
    <echo>Stop Tomcat</echo>
<java classname="org.apache.catalina.startup.Bootstrap" fork="true" classpathref="tomcat.class.path">
    <jvmarg value="-Dcatalina.home=<TomcatHome>"/>
</java>
<sleep seconds="15"/>
</target>

<target name="tomcat-stop" depends="tomcat-check-status" if="tomcat.started">
    <echo>Start Tomcat</echo>
    <java classname="org.apache.catalina.startup.Bootstrap"     fork="true" classpathref="tomcat.class.path">
<jvmarg value="-Dcatalina.home=<TomcatHome>"/>
        <arg line="stop"/>
    </java>
    <sleep seconds="15"/>
</target>

<target name="tomcat-check-status">
    <condition property="tomcat.started">
        <socket server="localhost" port="8000"/>
    </condition>
</target>
<target name="deploy">
    <sequential>
        <antcall target="tomcat-stop"/>
            <echo>Deploy to server</echo>
            <copy todir="<TomcatHome>/webapps">
                <fileset dir="<Current directory of WarFiles>">
                <include name="*.war"/>
                </fileset>
            </copy>
        <antcall target="tomcat-start"/>
    </sequential>
</target>
</project>

这是您的管道脚本的外观:

dir("<directory of build.xml>") {
       stage('deploy'){
         def antHome = tool 'Ant <version>';
                withAnt(installation: 'Ant <version>') {

            bat "ant deploy"
            }
        }
        }
    }