misco
misco

Reputation: 1952

How to set war name on deploy phase to Nexus repository?

I have snapshot repository for storing snapshots with Nexus. Build pipeline consists from Jenkins with build job. The aim of this build job is deployment of an artifact (war file) to nexus. Everything works fine, but I want to rename output war. War filename has following structure:

artifactName-version-date.anynumbers-anynumber.war 
(example-1.0.1-20140925-120156-3.war)

I tried to set war name with maven-war-plugin in build configuration.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.0.2</version>
   <configuration>
       <warName>${build.name}</warName>
    </configuration>
 </plugin>

Desired war name should be in format e.g. example-en-1.0.1-20140925-120156-3.war1, where en is build profile. Property build.name is set on value example-en. But this configuration is ignored and war file is still stored to Nexus in undesirable format.

When I take a look on build log, there is log about successful upload war file to Nexus repository and there is bad name of war file. So I don't know where wrong configuration.

Maven command is mvn clean deploy -P en

Edit:

Here is part from console log, where example-en.war is copied to jenkins workspace. This is correct, but in last step is uploaded war file with different file name.

[INFO] 
[INFO] --- maven-war-plugin:2.0.2:war (default-war) @ example ---
[INFO] Exploding webapp...
[INFO] Assembling webapp example in /var/lib/jenkins/workspace/build/example/target/example-sk
[INFO] Copy webapp webResources to /var/lib/jenkins/workspace/build/example/target/example-sk
[INFO] Generating war /var/lib/jenkins/workspace/build/example/target/example-sk.war
[INFO] Building war: /var/lib/jenkins/workspace/build/example/target/example-sk.war
[INFO] 
[INFO] --- maven-install-plugin:2.3:install (default-install) @ example ---
[INFO] Installing /var/lib/jenkins/workspace/build/example/target/example-sk.war to /var/lib/jenkins/.m2/repository/com/example/example/1.0.1-SNAPSHOT/example-1.0.1-SNAPSHOT.war
[INFO] Installing /var/lib/jenkins/workspace/build/example/pom.xml to /var/lib/jenkins/.m2/repository/com/example/example/1.0.1-SNAPSHOT/example-1.0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ example ---
Downloading: http://127.0.0.1:8082/nexus/content/repositories/example-snapshots/com/example/example/1.0.1-SNAPSHOT/maven-metadata.xml
774/774 B   

Downloaded: http://127.0.0.1:8082/nexus/content/repositories/example-snapshots/com/example/example/1.0.1-SNAPSHOT/maven-metadata.xml (774 B at 3.4 KB/sec)
Uploading: http://127.0.0.1:8082/nexus/content/repositories/example-snapshots/com/example/example/1.0.1-SNAPSHOT/example-1.0.1-20140925.120156-3.war

Upvotes: 1

Views: 5164

Answers (2)

Vic
Vic

Reputation: 318

I think you should be looking into Nexus repository settings. Have you ever tried uploading anything manually? You'd see that whatever the file name is, after you upload it to Nexus repository it is available for download as "${artifactId}-${version}-${classifier}.${packaging}"

Unfortunately I don't have access to Nexus now and I can't check if it's possible to set it to keep the names.

The second approach would be to set the tag to the desired format (since it accepts variables ${}), that would be workaround to Nexus naming convention (putting variables in version section is considered deprecated if i remember correctly though).

Upvotes: 1

Akhil
Akhil

Reputation: 479

You don't need to add a plugin for this. Just add a property <finalName> to <build>..</build> like this

<build>
    <finalName>example-en-${build.name}</finalName>
    ......
</build>

Upvotes: 0

Related Questions