18

We have numerous Java projects, which are CI built with Jenkins. These are deployed to our own Nexus server just fine. The problem is, we need to provide these libraries to a third party, but without the source code. So for each project, in Nexus we have:

  • Releases repository for our devs (includes deployed source code)
  • Snapshots repositories for our devs (includes deployed source code)
  • Third party release repository (only JAR + POM)
  • (and would be good to have): Third party snapshot repository (only JAR + POM) for third party nightly builds

The question is: how is this usually handled in Jenkins/Nexus world? I'd prefer to have one single Job in Jenkins which handles the CI build and the release (artefact deployment) process "automatically". Currently I'm using multiple <distributionManagement> profiles in our "main root pom.xml" (included by all projects):

[...]
<profiles>
    <profile>
        <id>default</id>
        <distributionManagement>
            <repository>
                <id>releases</id>
                <name>Release</name>
                <url>http://path/to/nexus/content/repositories/releases/</url>
            </repository>
            <snapshotRepository>
                <id>snapshots</id>
                <name>Snapshot</name>
                <url>http://path/to/nexus/content/repositories/snapshots/</url>
                <uniqueVersion>false</uniqueVersion>
            </snapshotRepository>
        </distributionManagement>
    </profile>
    <profile>
        <id>third-party</id>
        <distributionManagement>
            <repository>
                <id>releases</id>
                <name>Release</name>
                <url>http://path/to/nexus/content/repositories/third-party/</url>
            </repository>
            <snapshotRepository>
                <id>snapshots</id>
                <name>Snapshot</name>
                <url>http://path/to/nexus/content/repositories/third-party-snapshots/</url>
                <uniqueVersion>false</uniqueVersion>
            </snapshotRepository>
        </distributionManagement>
    </profile>
</profiles>

From the Maven docs, it seems to be no way of using multiple repositories during the same build lifecycle, not to mention the fact that we need/don't need the source based on the target repo.

I can do a trick with creating a Job in Jenkins, with the Maven "Goals and options": clean deploy -P third-party and then adding the Post-build action - "Deploy artifacts to Maven repository" with the "default" data - but in this case, only SNAPSHOTs are going to both repo and artefacts released via Jenkins Maven Release Plug-in are going into one repository only.

Any practical ideas how can I do this without overcomplicating our CI job hierarchy?

Thanks in advance!

Rob Kielty
  • 7,958
  • 8
  • 39
  • 51
Siaynoq
  • 452
  • 1
  • 5
  • 13
  • possible duplicate of [Multiple deployments in maven](http://stackoverflow.com/questions/635154/multiple-deployments-in-maven) – Kate Gregory Nov 26 '12 at 14:22
  • Yeah, I checked that. Actually, the Wagon plugin recommended below might have the same functionality with `merge-maven-repos`, which might be usable for the other post. So worst case we need to implement a custom plugin, I was just wondering if there is a "common way" of doing it even with the help of Jenkins. – Siaynoq Nov 26 '12 at 15:16

2 Answers2

5

You can just handle this all in Nexus. Create a repository target that contains a pattern like the one used in the preconfigured example "All but sources (Maven 2)" and narrow that target down even further with another pattern that restricts the groupid, artifactid and maybe even version.

Then create a privilege that uses that repository target and assign it to the user or role you want to have the respective access.

No need to do multiple deployments or some such..

See http://books.sonatype.com/nexus-book/reference/repository-targets.html

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • Thanks! After understanding the repo-target/privilege/role/user hierarchy it was a piece of cake setting up Nexus to restrict specific users from accessing the source jars. I had some confusion about the difference of "view" (->able to view the directories) and "read" (->able to download the files), but otherwise it was really easy. – Siaynoq Nov 27 '12 at 09:24
  • The link is broken. – Cleankod May 05 '17 at 11:43
  • Fixed the link @CleanKod – Manfred Moser May 10 '17 at 15:20
0

You can use Maven Wagon Plugin and upload a single jar to a remote location on deploy phase.

Troy Daniels
  • 3,270
  • 2
  • 25
  • 57
Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
  • Thanks for the idea. This indeed looks useful, but I couldn't find any working example which basically "replicates" (or uploads) a subset of files (in this case main jar and pom.xml) to another repo (and to the same place in the hierarchy). Any hints? – Siaynoq Nov 26 '12 at 14:54