Jenkinsfile Multibranch Pipeline Github Maven Checkout Directory Issues

826 views
Skip to first unread message

Tony Murphy

unread,
Aug 17, 2016, 5:02:56 AM8/17/16
to jenkins...@googlegroups.com
Hi

I'm using the new Jenkins Pipelines and I need some help.

I was under the illusion that once I setup my multi branch pipeline that was it as far as checkouts and branch management was concerned. But it seems that I was mistaken.

I had issues where for example mvn command was not running in the directory were the code was checkout out to. The command seemed to be running in a <branch_name> folder, while the code was in a sibling folder with a <branch_name>@scripts name (hope that makes sense)

`checkout scm` does not work for me btw

I would be grateful if someone could confirm I'm on the right track, could suggest improvements or confirm that it won't always be like this :)

#!groovy

githubCredentials = 'github_credentials'
def projectBranch = "${env.BRANCH_NAME}"

node {

def javaHome = tool "java8" // ensure Java 8 is installed
def projectRepoURL = 'g...@github.com:tonymurphy/jenkins-test.git'
echo "${env.getEnvironment()}"
def mvnHome = tool "mvn-3.2.2"

wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {

stage "Checkout"
sh("git config --global credential.helper cache")
checkout([$class : 'GitSCM',
branches : [[name: projectBranch]],
extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'jenkins-test'], [$class: 'CheckoutOption', timeout: 100000]],
userRemoteConfigs: [[credentialsId: githubCredentials, url: projectRepoURL]]])

stage 'Build'
withEnv(["PATH+ACTIVATOR=${tool 'activator-1.3.x'}", "PATH+JDK=${javaHome}/bin", "JAVA_HOME=${javaHome}"]) {
dir("jenkins-test") {
sh "${mvnHome}/bin/mvn clean compile test "
step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])

}
}
}
}

Thanks!

Baptiste Mathus

unread,
Aug 17, 2016, 5:44:51 PM8/17/16
to jenkins...@googlegroups.com

Not sure I get what your actual issue is. Could you maybe rephrase it to say what you see, compared to what you expect, and provide the error logs and so on?

Cheers


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAORQRkVZKg0fh4oqcgi8CQKhfpJ6BGnBoHijP55xv1SUR2VF6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Tony Murphy

unread,
Aug 18, 2016, 5:00:23 AM8/18/16
to Jenkins Users, m...@batmat.net
Sorry, I wasn't clear

  1. I created a simple maven project (https://github.com/tonymurphy/jenkins-test), the Jenkins file did not have any checkout step (code sample below).
  2. I created a multibranch pipeline project using Jenkins 2. Jenkins then indexed the branches. I was able to use the Jenkins UI to run the build
  3. On running the build, ${mvnHome}/bin/mvn clean compile test failed, the error was pom.xml not found
  4. I determined that the mvn command had been running from the "wrong" directory
  5. I then had to add the checkout step, adding code to check out the branch, add also switch into code check out folder dir("jenkins-test")
  6. I really like the new Jenkins pipeline - but the additional steps were not obvious and unexpected. I suspect I'm missing something, and my "workaround" is heavy handed
-- broken Jenkins file

I hope this makes more sense

Thanks

#!groovy

node {

def javaHome = tool "java8" // ensure Java 8 is installed
def projectRepoURL = 'g...@github.com:tonymurphy/jenkins-test.git'
echo "${env.getEnvironment()}"
def mvnHome = tool "mvn-3.2.2"

wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Baptiste Mathus

unread,
Aug 19, 2016, 5:22:21 PM8/19/16
to jenkins...@googlegroups.com

Step 5, you say you added a checkout step, but can't see it. Why didn't you leave it? It's indeed required to have the sources.


To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d8ea5e81-5de8-4eac-b23b-94213f55e057%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages