0

I'm attempting to migrate our CI process from JobDSL to a multibranch pipelines setup. As a first step I've decided to just have the pipeline delegate back to the existing jobs (passing the required params) My pipeline looks like below (pseudo code)

stage('setup')
node('cotroller') {
  ...
}


stage('test') {
  parallel {
    'web' : {build job 'web-test' ..params...},
    'API' : {build job 'api-test' ..params...}
  }
}

stage('build') { 
  parallel {
    'web' : {build job 'web-build' ..params...},
    'API' : {build job 'api-build' ..params...}
  }
}

stage('publish') {
  node('controller'){
    sh './gradlew publishArtifacts'
  }
}

However Im getting issues with the last 'publish' stage. When it kicks off the gradle target it correctly reused the workspace from the 'setup' phase, but seems to execute in a 'durable' sub folder from the original checkout (i.e the past in the setup phase execute in /mnt/jenkins/workspace/<branchname>/<random_hash>/ however the last gradle target executes in a folder such as /mnt/jenkins/workspace/<branchname>/<random_hash>@tmp/durable-<hash>/script.sh) This is resulting in a gradlew not found error

I've tried playing around using the directory('/...'){...} but that doesnt seem to have resolved the issue...any help or guidance would be much appreciated!

KrisM82
  • 335
  • 2
  • 11

2 Answers2

1

Saving setup path

You can try to save working directory from setup stage, e.g.:

stage('setup')
node('cotroller') {
  def setupPath = pwd()
  ...
}


stage('test') {
  parallel {
    'web' : {build job 'web-test' ..params...},
    'API' : {build job 'api-test' ..params...}
  }
}

stage('build') { 
  parallel {
    'web' : {build job 'web-build' ..params...},
    'API' : {build job 'api-build' ..params...}
  }
}

stage('publish') {
  node('controller'){
    dir("${setupPath}") {
      sh './gradlew publishArtifacts'
    }
  }
}

Using Global Tool Configuration

The recommanded approach, according to Jenkins pipeliens tutorial, is to configure Gradle install path in the Jenkin's Global Tool configuration, name it anything (e.g. "Gradle") and then use it in your pipeline like this :

...

stage('publish') {
  node('controller'){
    def gradleHome = tool 'Gradle'        
    sh "${gradleHome}/bin/gradlew publishArtifacts'
  }
}
Pom12
  • 7,622
  • 5
  • 50
  • 69
  • As we are using gradle wrapper, the relative paths should be fine, as the wrapper is within the rood directory of the git checkout. – KrisM82 Oct 03 '16 at 09:00
0

The groovy syntax didn't work for me. Had to change it to:

stage('test') {
    parallel (
        'web' : {build 'web-test' ..params...},
        'API' : {build 'api-test' ..params...}
    )
}
myborobudur
  • 4,385
  • 8
  • 40
  • 61