jenkins java

技术提示#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在测试实例上运行测试
  • 仅当测试通过测试实例时,才将应用程序推入生产环境

让我们开始吧!

  1. 从技术提示#55中创建的WildFly git repo中删除现有的样板源代码,仅删除src目录。

    mywildfly> git rm -rf src/ pom.xml
    rm 'pom.xml'
    rm 'src/main/java/.gitkeep'
    rm 'src/main/resources/.gitkeep'
    rm 'src/main/webapp/WEB-INF/web.xml'
    rm 'src/main/webapp/images/jbosscorp_logo.png'
    rm 'src/main/webapp/index.html'
    rm 'src/main/webapp/snoop.jsp'
    mywildfly> git commit . -m"removing source and pom"
    [master 564b275] removing source and pom7 files changed, 647 deletions(-)delete mode 100644 pom.xmldelete mode 100644 src/main/java/.gitkeepdelete mode 100644 src/main/resources/.gitkeepdelete mode 100644 src/main/webapp/WEB-INF/web.xmldelete mode 100644 src/main/webapp/images/jbosscorp_logo.pngdelete mode 100644 src/main/webapp/index.htmldelete mode 100644 src/main/webapp/snoop.jsp
  2. 将新的远程设置为javaee7-continuous-delivery存储库:
    mywildfly> git remote add javaee7 https://github.com/arun-gupta/javaee7-continuous-delivery.git
    mywildfly> git remote -v
    javaee7 https://github.com/arun-gupta/javaee7-continuous-delivery.git (fetch)
    javaee7 https://github.com/arun-gupta/javaee7-continuous-delivery.git (push)
    origin  ssh://54699516ecb8d41cb8000016@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/ (fetch)
    origin  ssh://54699516ecb8d41cb8000016@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/ (push)
  3. 从新的遥控器中提取代码:
    mywildfly> git pull javaee7 master
    warning: no common commits
    remote: Counting objects: 62, done.
    remote: Compressing objects: 100% (45/45), done.
    remote: Total 62 (delta 14), reused 53 (delta 5)
    Unpacking objects: 100% (62/62), done.
    From https://github.com/arun-gupta/javaee7-continuous-delivery* branch            master     -> FETCH_HEAD* [new branch]      master     -> javaee7/master
    Merge made by the 'recursive' strategy..gitignore                                           |   6 +++README.asciidoc                                      |  15 ++++++pom.xml                                              | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++src/main/java/org/javaee7/sample/MyApplication.java  |   9 ++++src/main/java/org/javaee7/sample/Person.java         |  31 ++++++++++++src/main/java/org/javaee7/sample/PersonDatabase.java |  39 ++++++++++++++src/main/java/org/javaee7/sample/PersonResource.java |  29 +++++++++++src/main/webapp/index.jsp                            |  13 +++++src/test/java/org/javaee7/sample/PersonTest.java     |  77 ++++++++++++++++++++++++++++src/test/resources/arquillian.xml                    |  26 ++++++++++10 files changed, 442 insertions(+)create mode 100644 .gitignorecreate mode 100644 README.asciidoccreate mode 100644 pom.xmlcreate mode 100644 src/main/java/org/javaee7/sample/MyApplication.javacreate mode 100644 src/main/java/org/javaee7/sample/Person.javacreate mode 100644 src/main/java/org/javaee7/sample/PersonDatabase.javacreate mode 100644 src/main/java/org/javaee7/sample/PersonResource.javacreate mode 100644 src/main/webapp/index.jspcreate mode 100644 src/test/java/org/javaee7/sample/PersonTest.javacreate mode 100644 src/test/resources/arquillian.xml

    这将带来所有源代码,包括我们的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

    这里要注意的几点:

    1. 在OpenShift上构建应用程序时使用“ openshift”配置文件。 这是创建应用程序的WAR文件并将其部署到WildFly的地方。
    2. 添加了新的配置文件“ jenkins-openshift”,供OpenShift中的Jenkins实例(即将启用)使用它来运行测试。
    3. “ arquillian-openshift”依赖项与技术提示#55中使用的依赖项相同,并且允许在OpenShift的WildFly实例上运行Arquillian测试。
    4. 此配置文件引用将在“ arquillian.xml”中定义的“ jenkins-openshift”容器配置。

    更新的“ 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实例的配置中定义,并允许针对单独的测试节点运行测试。

  4. 在将更改推送到远程存储库之前,还需要完成两件事。 首先是创建一个WildFly Test实例,该实例可用于运行测试。 可以很容易地完成,如下所示:
    workspaces> rhc app-create mywildflytest jboss-wildfly-8
    Application Options
    -------------------
    Domain:     milestogo
    Cartridges: jboss-wildfly-8
    Gear Size:  default
    Scaling:    noCreating application 'mywildflytest' ... Artifacts deployed: ./ROOT.war
    doneWildFly 8 administrator added.  Please make note of these credentials:Username: adminITJt7YhPassword: yXP2mUd1w4_8run 'rhc port-forward mywildflytest' to access the web admin area on port 9990.Waiting for your DNS name to be available ... doneCloning into 'mywildflytest'...
    Warning: Permanently added the RSA host key for IP address '54.205.69.88' to the list of known hosts.Your application 'mywildflytest' is now available.URL:        http://mywildflytest-milestogo.rhcloud.com/SSH to:     546e3743ecb8d49ca9000014@mywildflytest-milestogo.rhcloud.comGit remote: ssh://546e3743ecb8d49ca9000014@mywildflytest-milestogo.rhcloud.com/~/git/mywildflytest.git/Cloned to:  /Users/arungupta/workspaces/javaee7/mywildflytestRun 'rhc show-app mywildflytest' for more details about your app.

    请注意,这里的域是milestogo ,应用程序名称是mywildflytest ,SSH用户名称是546e3743ecb8d49ca9000014 。 这些将传递给Arquillian进行测试。

  5. 其次是启用和配置Jenkins。在您的OpenShift控制台中 ,选择“ mywildfly”应用程序,然后单击“ Enable Jenkins”链接,如下所示:

    请记住,这不是您的Test实例,因为所有源代码都位于先前创建的实例上。提供适当的名称,例如jenkins-milestogo.rhcloud.com(在我的情况下),然后单击“添加Jenkins”按钮。 这将提供一个Jenkins实例(如果尚未存在的话),并使用脚本配置项目以构建和部署应用程序。 记下名称和密码凭据。

  6. 使用凭据登录到您的Jenkins实例。在这种情况下,选择适当的版本“ mywildfly-build”。 向下滚动到“ Build”部分,然后在Execute Shell中的“#Run tests here”之后添加以下脚本:
    export ARQ_DOMAIN=milestogo
    export ARQ_SSH_USER_NAME=546e3743ecb8d49ca9000014
    export ARQ_APPLICATION=mywildflytest
    mvn test -Pjenkins-openshift

    单击“保存”以保存配置。 这将允许在Test实例上运行Arquillian测试。 如果测试通过,则将部署该应用程序。 如果测试失败,则该步骤之后的所有步骤均不会执行,因此不会部署该应用程序。

  7. 现在让我们将更改推送到远程仓库:
    mywildfly> git push
    Counting objects: 68, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (49/49), done.
    Writing objects: 100% (61/61), 8.85 KiB | 0 bytes/s, done.
    Total 61 (delta 14), 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: SUCCESS
    remote: New build has been deployed.
    remote: -------------------------
    remote: Git Post-Receive Result: success
    remote: Deployment completed with status: success
    To ssh://546cef93ecb8d4ff37000003@mywildfly-milestogo.rhcloud.com/~/git/mywildfly.git/e8f6c61..e9ad206  master -> master

    点的数量表示等待特定任务,并且很可能会因运行不同而有所不同。 而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

jenkins java

jenkins java_具有WildFly,Arquillian,Jenkins和OpenShift的Java EE 7部署管道相关推荐

  1. 具有WildFly,Arquillian,Jenkins和OpenShift的Java EE 7部署管道

    技术提示#54展示了如何Arquillianate(Arquillianize?)一个现有的Java EE项目并在WildFly在已知主机和端口上运行的远程模式下运行这些测试. 技术提示#55展示了当 ...

  2. 使用Jenkins,GitHub和Docker的最先进的持续集成和部署管道

    搭建舞台 在过去的两年中,我一直在从事Node.js项目. 我们使用GitHub进行源管理,使用Jenkins进行持续集成. 我们还有一个基于Docker和Terraform的部署工具 . 在此期间, ...

  3. OpenShift上的Java EE工作流(技术提示#64)

    该网络研讨会展示了如何使用WildFly , JBoss Tools , Forge , Arquillian和OpenShift在OpenShift上创建Java EE工作流. 具体来说,它谈论: ...

  4. Jenkins 2.16.3默认没有Launch agent via Java Web Start,如何配置使用

    问题:Jenkins 2.16.3默认没有Launch agent via Java Web Start,如下图所示,而这种启动方式在Windows上是最方便的. 如何设置才能让出来呢? 打开&quo ...

  5. Jenkins遇到问题一:jenkins配置权限不对导致无法登陆或者空白页面解决办法

    Jenkins遇到问题一:jenkins配置权限不对导致无法登陆或者空白页面解决办法 参考文章: (1)Jenkins遇到问题一:jenkins配置权限不对导致无法登陆或者空白页面解决办法 (2)ht ...

  6. jenkins docker 安装_docker 安装 Jenkins

    Jenkins docker市场 docker pull jenkins/jenkins:lts docker inspect ba607c18aeb7 查看版本 mkdir /home/jenkin ...

  7. Jenkins怎么安装、使用Jenkins构建、部署spring boot项目

    一.环境搭建 本次实验的环境为Ubuntu 16.04,Jenkins 2.8.3 1.安装ssh sudo apt-get update # 更新软件源 sudo apt-get install o ...

  8. jenkins 启动_CentOS 7 安装 Jenkins

    准备工作 首选需要安装JAVA环境 https://www.cnblogs.com/stulzq/p/9286878.html 如果你的系统没有自带git,那么也需要安装一个 yum install ...

  9. jboss4 java_带有JBoss工具的OpenShift 3上的Java EE 7应用程序

    jboss4 java 您可以使用最新版本的JBoss Tools OpenShift插件在Eclipse中创建和管理OpenShift应用程序. 他们要么预先捆绑了最新的 JBoss Develop ...

最新文章

  1. 【异常】org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
  2. 02-基于注解的入门案例
  3. c++代码小游戏_用Python编写一个打乒乓球小游戏
  4. python插件化设计_Python打造出适合自己的定制化EclipseIDE
  5. Substring Removal
  6. asp.net Mvc 使用NPOI导出Excel文件
  7. java 发送邮件昵称_javaMail发送邮件设置发件人中文昵称
  8. 光纤收发器的详细选择方法
  9. Java打造一款SSH客户端,已开源!
  10. Loadrunner的使用
  11. Git Tag 使用
  12. 数据结构笔记(二十六)-- 图的存储
  13. 2017.11.24 Stm8L151-factory
  14. php 写聊天室源码,php写的简易聊天室代码
  15. 陈经纶2021年高考成绩查询时间,2020北京市地区高考成绩排名查询
  16. matlab空间光调制器,空间光调制器原理与应用
  17. 香港中文大学9(深圳)医学院李丛磊组招收博后/科研助理/博士生
  18. Python词法分析器实现
  19. JS: prompt() 输入框 confim()确认框 alert() 提示框
  20. crh寄存器_牛人的STM32学习笔记(寄存器版本).doc

热门文章

  1. nssl1468-V【状压,数学期望,dfs】
  2. jzoj4786-[NOIP2016提高A组模拟9.17]小a的强迫症【数论】
  3. jzoj4231-寻找神格【线段树,数学】
  4. ssl1197-质数和分解【dp练习】
  5. codeforces1552 D. Array Differentiation(思维+暴力)
  6. SpringCloud Zuul(一)之介绍
  7. 汇编语言(三十二)之读写文件
  8. JSP JavaBean
  9. 分布式系统之消息队列
  10. JAVA面试常考系列八