4

I was wondering if there is a Hudson/Jenkins plugin that ties repository artifacts to the build that created them? I was looking at the question "remove artifacts from nexus repository" and thinking that deleting a build in Jenkins should also offer the option to remove the artifacts the build created.

We are currently running Jenkins 1.447 and the Nexus Open Source 1.9.2.3. Our Jenkins builds create artifacts in our Nexus repository using the maven deploy goal. I appears that once those artifacts have been deployed, there is no similarly automated mechanism to remove them. We would like to tie the Jenkins build to its Nexus artifacts. I figure if we have decided to remove the build from Jenkins, we have no use for the build and therefore, have no need to store the artifacts for that build either. We would like deleting the build to trigger deleting the Nexus artifacts.

If there's nothing available I figure I could start writing something, but I wanted to check and see how others handle this.

Community
  • 1
  • 1
Randolph
  • 451
  • 10
  • 24
  • Which kind of artifacts would you like to delete? – khmarbaise Apr 11 '12 at 07:17
  • Are you talking about SNAPSHOT's or releases ? – khmarbaise Apr 11 '12 at 09:53
  • Sorry for the delay. These would be releases. We version the artifact based on the hudson/jenkins build number. As you can imagine, over time this can get quite large on a multi-module application. – Randolph Apr 17 '12 at 22:25
  • It sounds like a misuse of the idea of release builds and SNAPSHOT's in Maven and of course for Nexus as well, cause once a release has been deployed it should never been deleted. – khmarbaise Apr 18 '12 at 19:20
  • @khmarbaise Links to best practices documentation on this would be helpful. Thanks! – Randolph Apr 18 '12 at 22:50
  • I think you know: http://www.sonatype.com/books/mvnref-book/reference/ and http://www.sonatype.com/index.php/Support/Books/Maven-By-Example? – khmarbaise Apr 19 '12 at 06:21

4 Answers4

0

You can purge artifacts from a local repository via the maven-dependency-plugin.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • According to the description on this plugin it will, "Remove the project dependencies from the local repository, and optionally re-resolve them." I'm looking to "synchronize" artifacts in Nexus with my builds in Jenkins. – Randolph Apr 11 '12 at 08:31
  • In Jenkins you can define to let maven use the repository of the server (user under which Jenkins runs) or locally based on the build which can be configured based on your Maven plugin which you use. The synchronization is done by your build. So what i don't understand what you really want to achieve. – khmarbaise Apr 18 '12 at 07:11
  • I've updated my question a bit hopefully making it more clear. Maybe there are some settings that you're speaking of that I'm missing? – Randolph Apr 18 '12 at 18:53
0

If you have a release it does not make sense to number it based on the numbers of the build server. The usual use case is to use SNAPSHOT's for exactly this purpose. Furthermore the usual use case is to delete SNAPSHOT's based on a scheduled task after a time from Nexus but releases will never be deleted from Nexus.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
0

Since you know the name of the release, you could build a custom job or trigger to use a wget command to delete the artifact from the nexus repository.

As the proper user in Nexus you do have the ability to delete release artifacts, not just SNAPSHOTS.

sjakubowski
  • 2,913
  • 28
  • 36
0

you can use the REST API from Nexus to build your own Jenkins Plugin that does that Job for you. You could store the Jenkins Build Job number using the Nexus custom-metadata plugin. Once the build is deleted you can have your custom Jenkins Plugin delete all artifacts in Nexus that have that build number in their metadate. I had a similar Problem and wrote a custom Jenkins Plugin. Have a look at the tutorial and the source code on github. It should be pretty straight forward.

Tutorial: http://blog.codecentric.de/en/2012/08/tutorial-create-a-jenkins-plugin-to-integrate-jenkins-and-nexus-repository/

Sourcecode: https://github.com/marcelbirkner/nexus-metadata-plugin/

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Marcel
  • 16
  • 1
  • There are a number of ins and outs of why and how, but this is the answer and what I finally ended up doing. – Randolph Nov 01 '12 at 20:35