一直想實現自動部署,這裏說的自動部署,是指點擊一個按鈕(或定時執行),讓計算機將最新的應用程序發佈到相應的環境(UAT或PRD)中。java
自動部署的意義web
自動部署能省去繁瑣的人工發佈步驟;如配置得當,發佈的執行穩定性(成功率)會比較高。app
這樣主要有幾點意義:ide
咱們開發中經常使用的軟件組合爲:Java + SVN(版本控制工具) + Ant(編譯打包工具) + Weblogic(Web Server)。工具
因此我也是以這一套組合爲設想,再加上自動部署工具Jenkins。測試
你們用的工具不盡相同,但工具間的使用或遵循的規範相似,因此切換應該是可行的。好比如今使用的Web Server是Weblogic,須要切換成Tomcat或Jboss,應該問題不大(但本人沒試過- - !)。ui
之前作過上述的設想,但一直卡在Weblogic的更新問題上:如何使用腳本讓Weblogic更新咱們的應用程序。this
最近仔細看了Weblogic文檔,發現調用weblogic.Deployer能很好地知足個人需求。url
發佈的思路spa
那麼,自動部署的思路是,使用Jenkins做爲任務的總調度師
如何更新Weblogic部署的應用程序
weblogic.Deployer是class,因此執行時需附上對應classpath,JAR在$WLS_HOME/server/lib/weblogic.jar。
我使用redeploy的參數實現更新應用程序:
java -cp $WLS_HOME/server/lib/weblogic.jar weblogic.Deployer -adminurl t3://xx.xx.xx.xx:7001 -username weblogicusername -password weblogicpassword -name appname -redeploy
PS,附上weblogic.Deployer的幫助信息:
Usage: java weblogic.Deployer [options] [action] [Deployment units(s)]
where options include:
-help Print the standard usage message.
-version Print version information.
-adminurl <<protocol>://<server>:<port>> [option] Administration
server URL: default t3://localhost:7001
-username <username> [option] user name
-password <password> [option] password for the user
-userconfigfile <userconfigfile> [option] The user config file
contains the user security credentials; it
is administered by the weblogic.Admin tool
-userkeyfile <keyConfigFile> [option] The users key file; it is
administered by the weblogic.Admin tool.
-distribute [action] Distribute application to the
targets.
-start [action] Makes an already distributed
application available on a target.
-stop [action] Makes an application unavailable on
targets.
-redeploy [action] Replace a running application
partially or entirely.
-undeploy [action] Take an application out of service.
-deploy [action] Make an application available for
service.
-update [action] Update an application configuration
in place.
-examples [option] Displays example usage of this tool.
-name <application name> [option] Defaults to the basename of the
deployment file or directory.
-targets <<target(s)>> [option] A comma separated list of targets
for the current operation. If not specified,
all configured targets are used. For a new
application, the default target is the
administration server.
-plan <Deployment plan path> [option] Specifies location of
deployment plan
-library [option] Indicates that the unit being
deployed is a library. This option is
required when the application is a library.
-advanced Print advanced usage options.
The optional trailing arguments are deployment units and may
represent the archive being deployed, the name of a previously
deployed application or a list of files for a partial redeploy operation.