简体   繁体   English

Jenkins管道多分支问题在并行作业后重用节点类型

[英]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. 我正在尝试将我们的CI流程从JobDSL迁移到多分支管道设置。 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 当启动gradle目标时,它可以正确地重用'setup'阶段中的工作空间,但是似乎在原始结帐的'durable'子文件夹中执行(即,过去在setup阶段中在/mnt/jenkins/workspace/<branchname>/<random_hash>/但是最后一个gradle目标在/mnt/jenkins/workspace/<branchname>/<random_hash>@tmp/durable-<hash>/script.sh等文件夹中执行在gradlew中找不到错误

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: 您可以尝试在setup阶段保存工作目录,例如:

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 : 根据Jenkins pipeliens教程的建议 ,方法是在Jenkin的Global Tool configuration配置Gradle安装路径,将其命名为任何名称(例如“ Gradle ”),然后像这样在您的管道中使用它:

...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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