简体   繁体   中英

Jenkins pipeline multibranch issue reusing node type after parallel jobs

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 (ie 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!

Saving setup path

You can try to save working directory from setup stage, eg:

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 (eg " Gradle ") and then use it in your pipeline like this :

...

stage('publish') {
  node('controller'){
    def gradleHome = tool 'Gradle'        
    sh "${gradleHome}/bin/gradlew publishArtifacts'
  }
}

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...}
    )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM