Using Jenkins to publish tar.gz to Nexus

2019-02-21 02:52发布

问题:

This is problem I am trying to solve:

  1. checkout code from Github to a local directory D
  2. run configure command inside directory D
  3. create a tar.gz for directory
  4. upload taz.gz file to Nexus

I am stuck at step 3: - I can specify the version in Maven pom.xml file, but is there a way to automatically create a build version every time Jenkins is run? - If I specify tar.gz in pom.xml file, I would get: Unknown packaging: gz @ line 6, column 13

If I specify jar inside packaging, there is no error, and files are upload to Nexus successfully.

Any advice would help, thanks!

==

follow suggestion, I am using Assembly Plugin, but still having trouble create tar.gz for Directory RE

Here is my pom.xml:

<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.o$
<modelVersion>4.0.0</modelVersion>
<groupId>Auc</groupId>
<artifactId>RE</artifactId>
<version>1.0.0.112</version>
<!-- <packaging>tgz</packaging> -->
<name>RE Repository</name>
<url>http://nexus1.ccorp.com/nexus</url>
<build>
<plugins>
  <plugin>
     <artifactId>maven-assembly-plugin</artifactId>
     <version>2.6</version>
     <executions>
       <execution>
         <configuration>
           <descriptors>
             <descriptor>format.xml</descriptor>
           </descriptors>
         </configuration>
       </execution>
     </executions>
   </plugin>
 </plugins>
</build>
</project>

Here is my format.xml file, RE directory is where I checked out the code and want to create tar.gz for it

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>bundle</id>
    <formats>
       <format>tar.gz</format>
    </formats>
    <moduleSets>
            <moduleSet>
                    <sources>
                            <fileSets>
                                    <fileSet>
                                            <directory>/var/lib/jenkins/jobs/nightly_build/workspace/RE</directory>
                                    </fileSet>
                            </fileSets>
                    </sources>
            </moduleSet>
    </moduleSets>
    <includeBaseDirectory>false</includeBaseDirectory>

回答1:

Here is what we end up with:

 mvn deploy:deploy-file -DgroupId=Home -DartifactId=RE -Dversion=0.0.0.1-SNAPSHOT -Dpackaging=tar.gz -DrepositoryId=Auc -Durl=http://nexus1.ccorp.com/nexus/content/repositories/snapshots -Dfile=RE-0.0.0.1-SNAPSHOT.tar.gz

Make sure -DrepositoryId=Auc, Auc is the deployment id you set in your setting.xml

<server>
  <id>Auc</id>
  <username>deployment</username>
  <password>deployment123</password>
</server>


回答2:

You have to use the Maven Assembly Plugin to create the tar.gz and then you can deploy it as usual with

mvn clean deploy

and the right settings.xml available on Jenkins with credentails as needed for the deployment.