Jenkins 自动部署 websphere 8.5.5.13 - 技术博客

Jenkins 自动部署 websphere 8.5.5.13

作者:莫问前程 发布于:2018-11-14 14:01 Wednesday

使用  Websphere 的脚本工具   ws_ant 结合Jenkins 来自动部署 WAS项目

1.使用Jenkins打包Git 项目包

2.Jenkins 使用 ssh工具 上传War包到应用服务器

3.使用shell命令 执行 ws_ant  -f  install.xml 部署项目 并且完成启动

4.注意 在自动部署的时候 会遇到以下问题

    1.xml文件在安装之前会自动卸载已经存和要部署的应用名称一样的应用

     2.应用安装的过程中,安装完war包后需要一段时间来解压war包,所以使用 sleep 90s 来满足war包解压的时间,然后再运行 启动应用的xml文件

     3.可能会遇到was和要部署应用的war包冲突,需要在xml中配置 类加载的顺序



shell命令

#/bin/bash
/bin/sh  /opt/IBM/WebSphere/AppServer/bin/ws_ant.sh  -f /opt/IBM/Sec01.xml  #安装和配置加载类的顺序
sleep 90s
/bin/sh  /opt/IBM/WebSphere/AppServer/bin/ws_ant.sh  -f /opt/IBM/Sec01-start.xml  #启动应用


Sec01.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="wasant" basedir="." default="InstallAndStart">
  <property name="was.root" value="/opt/IBM/WebSphere/AppServer"/>
  <property name="wsanttasks.jar" value="${was.root}/plugins/com.ibm.ws.runtime.jar"/>
  <property name="app.name" value="ifp-security-service_war"/>
  <property name="ear.file" value="/opt/IBM/target/ifp-security-service.war"/>
  <property name="contextroot" value="/ifp_security_service"/>
  <property name="node" value="ifp-app-2Node01"/>
  <property name="cell" value="Cell01"/>
  <property name="server" value="server1"/>
  <property name="username" value="admin"/>
  <property name="password" value="admin"/>
  <property name="host" value="10.1.89.50"/>
  <property name="port" value="8879"/>
  <property name="port1" value="8880"/>
  <property name="conntype" value="SOAP"/>
  <property name="setDeployments" value="set deployments [$AdminConfig getid /Deployment:${app.name}/]"/>
  <property name="setDeploymentsObject" value="set deploymentObject [$AdminConfig showAttribute $deployments deployedObject]"/>
  <property name="setModules" value="set modules [$AdminConfig showAttribute $deploymentObject modules]"/>
  <property name="setModule" value="set module [string trim $modules ?{}?]"/>
  <property name="setClassLoaderMode" value="set classloader [$AdminConfig showAttribute $module classloader]"/>
  <property name="modifyClassLoaderMode" value="$AdminConfig modify $classloader {{mode PARENT_FIRST}}"/>
  <!-- 使用到的任务 -->
  <taskdef name="wsStartServer" classname="com.ibm.websphere.ant.tasks.StartServer" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsStopServer" classname="com.ibm.websphere.ant.tasks.StopServer" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsUninstallApp" classname="com.ibm.websphere.ant.tasks.UninstallApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsStartApp" classname="com.ibm.websphere.ant.tasks.StartApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsStopApp" classname="com.ibm.websphere.ant.tasks.StopApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsListApps" classname="com.ibm.websphere.ant.tasks.ListApplications" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsAdmin" classname="com.ibm.websphere.ant.tasks.WsAdmin" classpath="${wsanttasks.jar}"/>
  <!-- 卸载应用-->
  <target name="wsUninstallApp" description="UninstallApplication ${app.name}">
    <wsUninstallApp wasHome="${was.root}" application="${app.name}" conntype="${conntype}" host="${host}" port="${port}" user="${username}" password="${password}" failonerror="fasle"/>
  </target>
  <!-- 设置WEB模块类加载顺序-->
 <target name="wsSetClassLoaderMode" description="set classloader mode to${app.class.load.mode}">
 <echo>change class load moode to${app.class.load.mode}</echo>
 <wsAdmin user="${username}" command="${setDeployments};${setDeploymentsObject};${setModules};${setModule};${setClassLoaderMode};${modifyClassLoaderMode}" password="${password}" host="${host}" conntype="${conntype}" port="${port}" wasHome="${was.root}" />
 </target>
  <!-- 安装应用-->
  <target name="wsInstallApp" depends="wsUninstallApp" description="Install Application${app.name}">
    <wsInstallApp wasHome="${was.root}" ear="${ear.file}" options="-node ${node} -cell ${cell} -server ${server} -appname ${app.name} -contextroot ${contextroot} -usedefaultbindings" conntype="${conntype}" host="${host}" port="${port}" user="${username}" password="${password}" failonerror="true"/>
  </target>
  <!-- 启动应用1-->
  <target name="wsStartApp" description="StartApp Application ${app.name}">
    <wsStartApp wasHome="${was.root}" application="${app.name}" conntype="${conntype}" host="${host}" port="${port1}" user="${username}" password="${password}" failonerror="false"/>
  </target>
<!-- 启动应用2-->
  <target name="wsStartApp2" description="StartApp Application ${app.name}">
    <wsStartApp wasHome="${was.root}" application="${app.name}" conntype="${conntype}" host="${host}" port="${port1}" user="${username}" password="${password}" failonerror="true"/>
  </target>
  <!-- 实际的任务组合-->
  <target name="InstallAndStart" description="Install and Start ${app.name}">
    <antcall target="wsInstallApp"/>
    <antcall target="wsSetClassLoaderMode"/>
  </target>
</project>


Sec01-start.xml


<?xml version="1.0" encoding="utf-8"?>
<project name="wasant" basedir="." default="InstallAndStart">
  <property name="was.root" value="/opt/IBM/WebSphere/AppServer"/>
  <property name="wsanttasks.jar" value="${was.root}/plugins/com.ibm.ws.runtime.jar"/>
  <property name="app.name" value="ifp-security-service_war"/>
  <property name="ear.file" value="/opt/IBM/target/ifp-security-service.war"/>
  <property name="contextroot" value="/ifp_security_service"/>
  <property name="node" value="ifp-app-2Node01"/>
  <property name="cell" value="Cell01"/>
  <property name="server" value="server1"/>
  <property name="username" value="admin"/>
  <property name="password" value="admin"/>
  <property name="host" value="10.1.89.50"/>
  <property name="port" value="8879"/>
  <property name="port1" value="8880"/>
  <property name="conntype" value="SOAP"/>
  <!-- 使用到的任务 -->
  <taskdef name="wsStartServer" classname="com.ibm.websphere.ant.tasks.StartServer" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsStopServer" classname="com.ibm.websphere.ant.tasks.StopServer" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsUninstallApp" classname="com.ibm.websphere.ant.tasks.UninstallApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsStartApp" classname="com.ibm.websphere.ant.tasks.StartApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsStopApp" classname="com.ibm.websphere.ant.tasks.StopApplication" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsListApps" classname="com.ibm.websphere.ant.tasks.ListApplications" classpath="${wsanttasks.jar}"/>
  <taskdef name="wsAdmin" classname="com.ibm.websphere.ant.tasks.WsAdmin" classpath="${wsanttasks.jar}"/>
  <!-- 卸载应用-->
  <target name="wsUninstallApp" description="UninstallApplication ${app.name}">
    <wsUninstallApp wasHome="${was.root}" application="${app.name}" conntype="${conntype}" host="${host}" port="${port}" user="${username}" password="${password}" failonerror="fasle"/>
  </target>
  <!-- 安装应用-->
  <target name="wsInstallApp" depends="wsUninstallApp" description="Install Application${app.name}">
    <wsInstallApp wasHome="${was.root}" ear="${ear.file}" options="-node ${node} -cell ${cell} -server ${server} -appname ${app.name} -contextroot ${contextroot} -usedefaultbindings" conntype="${conntype}" host="${host}" port="${port}" user="${username}" password="${password}" failonerror="true"/>
  </target>
  <!-- 启动应用1-->
  <target name="wsStartApp" description="StartApp Application ${app.name}">
    <wsStartApp wasHome="${was.root}" application="${app.name}" conntype="${conntype}" host="${host}" port="${port1}" user="${username}" password="${password}" failonerror="true"/>
  </target>
<!-- 启动应用2-->
  <target name="wsStartApp2" description="StartApp Application ${app.name}">
    <wsStartApp wasHome="${was.root}" application="${app.name}" conntype="${conntype}" host="${host}" port="${port1}" user="${username}" password="${password}" failonerror="true"/>
  </target>
  <!-- 实际的任务组合-->
  <target name="InstallAndStart" description="Install and Start ${app.name}">
    <antcall target="wsStartApp"/>
  </target>
</project>





发表评论:

30 + 98 =

Powered by 木匠 鲁ICP备88888888号