0
votes

I have a simple Maven project that has to produce artifact e.g. some-artifact I also have a job in Jenkins that does simple maven deploy to our internal Nexus repository. This is the value set in Jenkins in "Maven goals and options" field for the job:

clean source:jar deploy

Lets assume that the version of my maven module is 1.0:

<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>some.group</groupId>
    <artifactId>some-artifact</artifactId>
    <version>1.0</version>
</project> 

Now, what I want to achieve is to detect that the artifact version is changed in SCM and to build this job each time version number is changed, e.g. after it is set to 1.1:

<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>some.group</groupId>
        <artifactId>some-artifact</artifactId>
        <version>1.1</version>
</project>

The final goal is to have last version of some-artifact deployed on Nexus as soon as possible.

Is there any configuration or Jenkins plugin that allows such detection and job trigger?

2
Why calling source:jar integrate in your your pom and do just mvn clean deploy ...You can configure jenkins to be triggered on a change in SCM ...That's the default way to handle such things.. - khmarbaise
source:jar is not so important, the point is to trigger the job. If I trigger it on every change from SCM, deploy goal will fail since the version is same like the previous one (fail is actually OK, but at this moment we don't have some "clever" version management). - user2310395

2 Answers

0
votes

I don't know if it could help, there are several plugin that integrate maven and Jenkins, so maybe one of them will have a build int feature to accomplish you need...

By the way doing this without a specific plugin there are many ways..You can use the ${POM_VERSION} variable, which was introduced with

https://issues.jenkins-ci.org/browse/JENKINS-18272

Then compare it with the previous one, the previous revision or an history and so on...This way you can run the job just if the version has been changed.

You also can use this parameter in combination with the parameterized trigger plugin:

https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin

Or you can accomplish this with a SVN hook, something like if the version has been changed trigger a Jenkins job, there could be a lot of ways to do this manually... Very bad this last option! But it works..

0
votes

Let's try to do this in a standard way "user2310395"...

How do you release you artifact? Maven release plugin or what else?

I'm asking this because i think that a standard "workflow" should be like below:

  1. Release an artifact (1.00-SNAPSHOT) to (1.00), using the maven release plugin.. Now as you know, this is just about to call a Maven goal, so why don't use Jenkins job to accomplish this? And you have plugin that help you with this, in case you need, for example: Jenkins Release plugin
  2. Once the Release job will run you won't need any other job, because the Maven release plugin itself will take care about the new release artifact into the Nexus tag repository..

So what am i missing, why can't you just follow the standard workflow?