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?

  • I could try to help you if you paste your config.xml for that jenkins job. – Danila Ladner Oct 5 '13 at 3:21
  • Ok, but it will have to wait until Monday, I don't have access to those systems outside the office. I'll post it up first thing on Monday morning. – quickshiftin Oct 5 '13 at 3:26
  • Thanks for your patience. Since the xml was close to 200 lines, I posted it on pastebin. pastebin.com/WfAuMAwJ – quickshiftin Oct 7 '13 at 16:01
  • Very interesting.., this morning builds started breaking from low perm size memory. I've changed /etc/sysconfig/jenkins, setting JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Xmx2048m -XX:MaxPermSize=512m"; haven't had this problem come up in the last 5 builds. Fingers crossed this solved it, but the solution seems as bizarre as the problem! – quickshiftin Oct 7 '13 at 21:59
  • Yeah i was looking at your xml, is it possible for you also give me that script you run and full log output of running jenkins job? – Danila Ladner Oct 7 '13 at 22:20

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] ------------------------------------------------------------------------
[INFO] Reactor Summary:

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!

| improve this answer | |
  • 1
    Looking through other ways to parse that out on the SO post, I've settled on egrep -v '^\[|Downloading:' | tr -d ' \n' for the filter which should be more flexible. – quickshiftin Oct 8 '13 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.