Francesco Marchioni
Francesco Marchioni

Reputation: 4328

Basic Jenkins Pipeline fails

I have a Jenkins 1.6 running on Openshift. I'm trying to build a simple Jenkins Pipeline, which builds from a Git repository:

node {
  git url: 'https://github.com/fmarchioni/kitchensink-example.git'
  def mvnHome = tool 'M3'
  sh "${mvnHome}/bin/mvn clean install"
}

When I try to build the Pipeline it fails with an unclear message:

[Pipeline] node
Running on master in /var/lib/jenkins/jobs/pipeline/workspace
[Pipeline] {
[Pipeline] git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/fmarchioni/kitchensink-example.git # timeout=10
Fetching upstream changes from https://github.com/fmarchioni/kitchensink-example.git
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://github.com/fmarchioni/kitchensink-example.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 90df980f2c86f9a59d872bc8650ecfd0800c51bd (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 90df980f2c86f9a59d872bc8650ecfd0800c51bd # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master 90df980f2c86f9a59d872bc8650ecfd0800c51bd
First time build. Skipping changelog.
[Pipeline] tool
[Pipeline] sh
[workspace] Running shell script
+ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/M3/bin/mvn clean install
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code -1
Finished: FAILURE

Do you have any idea of what could be wrong? Thanks

Upvotes: 1

Views: 2955

Answers (2)

Bill Packard
Bill Packard

Reputation: 76

Try using the withMaven step to bracket the command. This will allow the specification of the maven tool version and JDK, as well as additional configuration options.

  withMaven(jdk: '<JDK name>', maven: '<maven name>') {
  sh 'mvn clean install'
  }

It will also document the configuration in the build.log:

[Pipeline] withMaven
[withMaven] Options: []
[withMaven] Available options: 
[withMaven] use JDK installation <JDK name>
[withMaven] use Maven installation '<maven name>'
[Pipeline] sh
[workspace] Running shell script

You may want to look at using the Pipeline Syntax link. It can generate snippets that you can use for individual steps. It will display the options available for the withMaven step.

enter image description here

Upvotes: 0

Will Gordon
Will Gordon

Reputation: 3573

I would suspect that the particular shell script, mvn clean install, is erring out. If you can, try SSHing into the cartridge and try that Mavin command directly. You would be able to add debugging options (from https://books.sonatype.com/mvnref-book/reference/running-sect-options.html) and hopefully see some more helpful output!

Upvotes: 1

Related Questions