Jenkins - 从各种耳朵创建一个 tar.gz 并将其交付到远程服务器上 [英] Jenkins - create a tar.gz from various ear and deliver it on a distant server

查看:29
本文介绍了Jenkins - 从各种耳朵创建一个 tar.gz 并将其交付到远程服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Maven 构建,它为它构建的每个模块生成一个 target/myModule.ear.

I have a maven build which produces a target/myModule.ear for each module it builds.

我想创建一个 Jenkins 工作:

I want to create a Jenkins job which :

1) 使用mvn clean install"构建项目

2) 将所有耳朵存档到 tar.gz

3) 将此 tar.gz 传送到远程服务器上

我对詹金斯很陌生,所以我不知道如何做 2) 和 3).我能想到的唯一解决方案是创建一个脚本,但如果我这样做了,那么使用 Jenkins 就毫无意义了.

I am very new to Jenkins so I don't know how to do 2) and 3). The only solution I can come up with is to create a script, but if I do that there is no point in using Jenkins.

推荐答案

您需要一个父项目,其中包含一个 war/jar 和一个用于包装 war 的 ear 项目,然后是一个用于组装 tar.gz 的分发项目.

You need a parent project which has a war/jar and an ear project to wrap the war, then a distribution project to assemble the tar.gz.

>

父母看起来像:

parent looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.greg</groupId>
  <artifactId>ear-example</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
        <myproject.version>1.0-SNAPSHOT</myproject.version>
  </properties>

  <name>ear-example</name>
  <modules>
    <module>example-ear</module>
    <module>example-war</module>
    <module>distribution</module>
  </modules>

</project>

ear 项目依赖于 war 项目,看起来像:

ear project has dependency to the war project and looks like:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.greg</groupId>
    <artifactId>ear-example</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>example-ear</artifactId>
  <packaging>ear</packaging>

  <dependencies>
    <dependency>
      <groupId>com.greg</groupId>
      <artifactId>example-war</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
  </dependencies>

  <build>
   <plugins>
     <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.10.1</version>
        <configuration>
                <modules>
                        <webModule>
                                <groupId>com.greg</groupId>
                                <artifactId>example-war</artifactId>
                                <contextRoot>/appname</contextRoot>
                        </webModule>
                </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

分发项目如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.greg</groupId>
    <artifactId>ear-example</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>distribution</artifactId>
  <packaging>pom</packaging>

  <name>Distribution</name>

  <dependencies>
    <dependency>
      <groupId>com.greg</groupId>
      <artifactId>example-ear</artifactId>
      <version>${project.version}</version>
      <type>ear</type>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>distro-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>src/assembly/assembly.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

构建 zip 的 assembly.xml 如下所示:

The assembly.xml which builds the zip looks like:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">

  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>true</useAllReactorProjects>
      <binaries>
        <outputDirectory>modules/maven-assembly-plugin</outputDirectory>
        <unpack>false</unpack>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

您必须自己完成部署

这篇关于Jenkins - 从各种耳朵创建一个 tar.gz 并将其交付到远程服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆