具有WildFly,Arquillian,Jenkins和OpenShift的Java EE 7部署管道
技術提示#54展示了如何Arquillianate(Arquillianize?)一個現有的Java EE項目并在WildFly在已知主機和端口上運行的遠程模式下運行這些測試。 技術提示#55展示了當WildFly在OpenShift中運行時如何運行這些測試。 這兩個技巧都使用Maven配置文件來分隔“ pom.xml”中的適當Arquillian依賴關系和“ arquillian.xml”中的<container>配置,以定義WildFy在何處運行以及如何連接。
本技巧將展示如何在OpenShift中配置Jenkins以及如何從Jenkins調用這些測試。 讓我們首先看看它的作用!
從OpenShift上的Jenkins連接到OpenShift上的WildFly實例所需的配置與從本地計算機到OpenShift上的WildFly連接所需的配置類似。 此配置在“ arquillian.xml”中指定,我們可以指定一些參數,然后可以在Jenkins中定義這些參數。
概括地說,這是我們要做的:
- 使用在技術提示#54和#55中創建的代碼,并為Arquillian / Jenkins / OpenShift添加配置
- 啟用詹金斯
- 創建一個新的WildFly Test實例
- 配置Jenkins在測試實例上運行測試
- 僅當測試通過測試實例時,才將應用程序推入生產環境
讓我們開始吧!
這將帶來所有源代碼,包括我們的REST端點,網頁,測試,更新的“ pom.xml”和“ arquillian.xml”。 更新的“ pom.xml”具有兩個新的配置文件。
openshiftorg.apache.maven.pluginsmaven-war-plugin2.3falsedeploymentsROOTjenkins-openshiftmaven-surefire-plugin2.14.1jenkins-openshiftorg.jboss.arquillian.containerarquillian-openshift1.0.0.Final-SNAPSHOTtest這里要注意的幾點:
更新的“ src / test / resources / arquillian.xml”具有以下容器:
<container qualifier="jenkins-openshift"><configuration><property name="namespace">${env.ARQ_DOMAIN}</property><property name="application">${env.ARQ_APPLICATION}</property><property name="libraDomain">rhcloud.com</property><property name="sshUserName">${env.ARQ_SSH_USER_NAME}</property><property name="login">arungupta@redhat.com</property><property name="deploymentTimeoutInSeconds">300</property><property name="disableStrictHostChecking">true</property> </configuration> </container>此容器配置類似于技術提示#55中添加的容器配置。 唯一的區別是域名,應用程序名稱和SSH用戶名已參數化。 這些屬性的值在Jenkins實例的配置中定義,并允許針對單獨的測試節點運行測試。
注意這里的域是milestogo ,應用程序名稱是mywildflytest ,SSH用戶名稱是546e3743ecb8d49ca9000014 。 這些將傳遞給Arquillian進行測試。
請記住,這不是您的Test實例,因為所有源代碼都位于先前創建的實例上。提供適當的名稱,例如jenkins-milestogo.rhcloud.com(在我的情況下),然后單擊“添加Jenkins”按鈕。 這將提供一個Jenkins實例(如果尚未存在的話),并使用腳本配置該項目以構建和部署該應用程序。 記下名稱和密碼憑據。
單擊“保存”以保存配置。 這將允許在Test實例上運行Arquillian測試。 如果測試通過,則將部署該應用程序。 如果測試失敗,則該步驟之后的所有步驟均不會執行,因此不會部署該應用程序。
點的數量表示等待特定任務,并且很可能會因運行不同而有所不同。 而Jenkins控制臺( jenkins-milestogo.rhcloud.com/job/mywildfly-build/1/console )將輸出顯示為:
-------------------------------------------------------T E S T S ------------------------------------------------------- Running org.javaee7.sample.PersonTest Nov 20, 2014 2:54:56 PM org.jboss.arquillian.container.openshift.OpenShiftContainer start INFO: Preparing Arquillian OpenShift container at http://mywildflytest-milestogo.rhcloud.com Nov 20, 2014 2:55:48 PM org.jboss.arquillian.container.openshift.OpenShiftRepository push INFO: Pushed to the remote repository ssh://546e3743ecb8d49ca9000014@mywildflytest-milestogo.rhcloud.com/~/git/mywildflytest.git/ Nov 20, 2014 2:56:37 PM org.jboss.arquillian.container.openshift.OpenShiftRepository push INFO: Pushed to the remote repository ssh://546e3743ecb8d49ca9000014@mywildflytest-milestogo.rhcloud.com/~/git/mywildflytest.git/ Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 103.056 sec Nov 20, 2014 2:56:37 PM org.jboss.arquillian.container.openshift.OpenShiftContainer stop INFO: Shutting down Arquillian OpenShift container at http://mywildflytest-milestogo.rhcloud.com Results :Tests run: 2, Failures: 0, Errors: 0, Skipped: 0[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3:13.069s [INFO] Finished at: Thu Nov 20 14:57:34 EST 2014 [INFO] Final Memory: 10M/101M [INFO] ------------------------------------------------------------------------ + /usr/libexec/openshift/cartridges/jenkins/bin/git_ssh_wrapper.sh 546e36e5e0b8cd4e2a000007@mywildfly-milestogo.rhcloud.com 'gear stop --conditional' Warning: Permanently added 'mywildfly-milestogo.rhcloud.com,10.5.171.43' (RSA) to the list of known hosts. Stopping gear... Stopping wildfly cart Sending SIGTERM to wildfly:418673 ... + rsync --delete-after -azO -e /usr/libexec/openshift/cartridges/jenkins/bin/git_ssh_wrapper.sh /var/lib/openshift/546e46304382ec3f29000012//.m2/ '546e36e5e0b8cd4e2a000007@mywildfly-milestogo.rhcloud.com:~/.m2/' Warning: Permanently added 'mywildfly-milestogo.rhcloud.com,10.5.171.43' (RSA) to the list of known hosts. + rsync --delete-after -azO -e /usr/libexec/openshift/cartridges/jenkins/bin/git_ssh_wrapper.sh /var/lib/openshift/546e46304382ec3f29000012/app-root/runtime/repo/deployments/ '546e36e5e0b8cd4e2a000007@mywildfly-milestogo.rhcloud.com:${OPENSHIFT_REPO_DIR}deployments/' Warning: Permanently added 'mywildfly-milestogo.rhcloud.com,10.5.171.43' (RSA) to the list of known hosts. + rsync --delete-after -azO -e /usr/libexec/openshift/cartridges/jenkins/bin/git_ssh_wrapper.sh /var/lib/openshift/546e46304382ec3f29000012/app-root/runtime/repo/.openshift/ '546e36e5e0b8cd4e2a000007@mywildfly-milestogo.rhcloud.com:${OPENSHIFT_REPO_DIR}.openshift/' Warning: Permanently added 'mywildfly-milestogo.rhcloud.com,10.5.171.43' (RSA) to the list of known hosts. + /usr/libexec/openshift/cartridges/jenkins/bin/git_ssh_wrapper.sh 546e36e5e0b8cd4e2a000007@mywildfly-milestogo.rhcloud.com 'gear remotedeploy' Warning: Permanently added 'mywildfly-milestogo.rhcloud.com,10.5.171.43' (RSA) to the list of known hosts. Preparing build for deployment Deployment id is dff28e58 Activating deployment Deploying WildFly Starting wildfly cart Found 127.12.255.129:8080 listening port Found 127.12.255.129:9990 listening port /var/lib/openshift/546e36e5e0b8cd4e2a000007/wildfly/standalone/deployments /var/lib/openshift/546e36e5e0b8cd4e2a000007/wildfly /var/lib/openshift/546e36e5e0b8cd4e2a000007/wildfly CLIENT_MESSAGE: Artifacts deployed: ./ROOT.war Archiving artifacts Finished: SUCCESS可以查看Jenkins的日志文件,如下所示:
Nov 20, 2014 2:51:11 PM hudson.plugins.openshift.OpenShiftCloud provision INFO: Provisioning new node for workload = 2 and label = mywildfly-build in domain milestogo Nov 20, 2014 2:51:11 PM hudson.plugins.openshift.OpenShiftCloud getOpenShiftConnection INFO: Initiating Java Client Service - Configured for OpenShift Server https://openshift.redhat.com Nov 20, 2014 2:51:11 PM com.openshift.internal.client.RestService request INFO: Requesting GET with protocol 1.2 on https://openshift.redhat.com/broker/rest/api Nov 20, 2014 2:51:11 PM com.openshift.internal.client.RestService request INFO: Requesting GET with protocol 1.2 on https://openshift.redhat.com/broker/rest/user Nov 20, 2014 2:51:11 PM com.openshift.internal.client.RestService request. . .INFO: Checking availability of computer hudson.plugins.openshift.OpenShiftSlave@8ce21115 Nov 20, 2014 2:53:35 PM com.openshift.internal.client.RestService request INFO: Requesting GET with protocol 1.2 on https://openshift.redhat.com/broker/rest/domain/milestogo/application/mywildflybldr/gear_groups Nov 20, 2014 2:53:35 PM hudson.plugins.openshift.OpenShiftComputerLauncher launch INFO: Checking SSH access to application mywildflybldr-milestogo.rhcloud.com Nov 20, 2014 2:53:35 PM hudson.plugins.openshift.OpenShiftComputerLauncher launch INFO: Connecting via SSH '546e46304382ec3f29000012' 'mywildflybldr-milestogo.rhcloud.com' '/var/lib/openshift/546e393e5973ca0492000070/app-root/data/.ssh/jenkins_id_rsa' Nov 20, 2014 2:53:35 PM hudson.slaves.NodeProvisioner update INFO: mywildfly-build provisioningE successfully completed. We have now 2 computer(s) Nov 20, 2014 2:53:35 PM hudson.plugins.openshift.OpenShiftComputerLauncher launch INFO: Connected via SSH. Nov 20, 2014 2:53:35 PM hudson.plugins.openshift.OpenShiftComputerLauncher launch INFO: Exec mkdir -p $OPENSHIFT_DATA_DIR/jenkins && cd $OPENSHIFT_DATA_DIR/jenkins && rm -f slave.jar && wget -q --no-check-certificate https://jenkins-milestogo.rhcloud.com/jnlpJars/slave.jar Nov 20, 2014 2:53:42 PM hudson.plugins.openshift.OpenShiftComputerLauncher launch INFO: Slave connected. Nov 20, 2014 2:58:24 PM hudson.model.Run execute INFO: mywildfly-build #1 main build action completed: SUCCESS 這表明該應用程序已成功部署在mywildfly-milestogo.rhcloud.com/index.jsp上 ,如下所示:
現在更改“ src / main / webapp / index.jsp”以顯示不同的標題。 并更改“ src / test / java / org / javaee7 / sample / PersonTest.java”以使其中一項測試失敗。 進行“ git commit”和“ git push”會在命令行上顯示以下結果:
mywildfly> git commit . -m"breaking the test" [master ff2de09] breaking the test2 files changed, 2 insertions(+), 2 deletions(-) mywildfly> git push Counting objects: 23, done. Delta compression using up to 8 threads. Compressing objects: 100% (8/8), done. Writing objects: 100% (12/12), 771 bytes | 0 bytes/s, done. Total 12 (delta 5), reused 0 (delta 0) remote: Executing Jenkins build. remote: remote: You can track your build at https://jenkins-milestogo.rhcloud.com/job/mywildfly-build remote: remote: Waiting for build to schedule.......Done remote: Waiting for job to complete.....................................................................................................................................................................Done remote: FAILED remote: !!!!!!!! remote: Deployment Halted! remote: If the build failed before the deploy step, your previous remote: build is still running. Otherwise, your application may be remote: partially deployed or inaccessible. remote: Fix the build and try again. remote: !!!!!!!! remote: An error occurred executing 'gear postreceive' (exit code: 1) remote: Error message: CLIENT_ERROR: Failed to execute: 'control post-receive' for /var/lib/openshift/546e36e5e0b8cd4e2a000007/jenkins-client remote: remote: For more details about the problem, try running the command again with the '--trace' option. To ssh://546e36e5e0b8cd4e2a000007@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/d618fad..ff2de09 master -> master要注意的關鍵聲明是,測試失敗后,將停止部署。 您可以通過重新訪問mywildfly-milestogo.rhcloud.com/index.jsp并檢查更新后的“ index.jsp”是否不可見來驗證這一點。
簡而言之,測試通過,網站已更新。 測試失敗,該網站未更新。 因此,您已經使用WildFly,OpenShift,Arquillian和Jenkins為Java EE 7建立了一個簡單的部署管道!
翻譯自: https://www.javacodegeeks.com/2014/12/deployment-pipeline-for-java-ee-7-with-wildfly-arquillian-jenkins-and-openshift.html
總結
以上是生活随笔為你收集整理的具有WildFly,Arquillian,Jenkins和OpenShift的Java EE 7部署管道的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何使用单例EJB,Ehcache和MB
- 下一篇: 曝尼康复古无反相机ZF 9月20日左右发