Maven interfering with Jenkins post build script

Jenkinsmaven

I have a Jenkins Maven job that has a post build script written in BASH. Periodically, while the post script is running, it seems like some sort of Maven operation is interfering with the BASH script causing the build to fail.

Here's some sample output from the Jenkins console

+ version_override='Downloading: http://clojars.org/repo/org/apache/maven/plugins/maven-metadata.xml
Downloading: http://clojars.org/repo/org/codehaus/mojo/maven-metadata.xml
Downloading: http://oss.sonatype.org/content/repositories/releases/org/apache/maven/plugins/maven-metadata.xml
Downloading: http://oss.sonatype.org/content/repositories/releases/org/codehaus/mojo/maven-metadata.xml

See how my BASH variable appears to be getting assigned a value from the Maven download? Now I won't say for certain that's what's going on. Maybe there's just two output streams going to the console simultaneously, one from Maven updating the repo, another from my BASH post build script. Either way, the Maven download seems to be interfering with my BASH script as it eventually crashes the build.

+ read config_path
+ '[' '!' -z http://clojars.org/repo/org/apache/maven/plugins/maven-metadata.xml ']'
+ http://clojars.org/repo/org/apache/maven/plugins/maven-metadata.xml
/usr/share/build-utils/lib/java.sh: line 115: http://clojars.org/repo/org/apache/maven/plugins/maven-metadata.xml: No such file or directory

That definitely looks like Maven output is creeping into my BASH script!

I'm almost positive this is Maven looking for updates. The strange thing is why would that run in parallel with a post build script. And even then, how is it possible that it would interfere with the runtime of said script? Truly bizarre!

Another reason I'm sure there's nothing wrong with my post build script. Every time this error comes up, I run the build again and it works. It's only when Maven is updating that the build fails.

I don't care if Maven wants to look for updates, but is there some way to configure it so that repo updates happen before my post build script?

Best Answer

Finally figured it out! I'm using a Maven plugin to extract the module version via a Maven plugin, based on this SO article.

The command produces output like this

[INFO] --- maven-help-plugin:2.1.1:evaluate (default-cli) @ master-parent ---
[INFO] No artifact parameter specified, using 'com.myorg:master-parent:pom:0.3.02' as project.
[INFO] 
0.3.02
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 

My initial BASH call to extract the version number

version_override=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v '[INFO]')

However, every so often (and yet unsure where to control this), Maven will reach out for updates to modules (I think). This is where the spurious Downloading output comes from, which mucks with my assignment from above.

I've now revised the command as follows

version_override=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | egrep -v '[INFO]|Downloading:' | tr -d ' \n')

Likely still not bullet proof though, who knows what other output could come from this command, for example some day instead of leading [INFO] lines, maybe it spits out [ERROR] or something...

Anyway, it's tightened down for the time being. I really did think this was a Jenkins/Maven issue at first, but turns out it was just a BASH scripting issue!

Related Topic