Jenkins Scripted Pipeline - 在节点分配工作区之前指定工作区目录

ruc*_*ckc 6 jenkins jenkins-pipeline

我有一个多分支管道,在一个脚本管道(来自库)中定义,它协调大约 100 个构建,每个构建跨多个从属(不同的操作系统)。操作系统之一是 Windows,它具有 255 个字符的路径限制。因为我们的一些作业中有大约 200 个字符路径(我们无法控制,因为它是供应商提供的地狱),所以我需要更改 Windows 从站上的步骤/节点工作区,最好使用 node()步骤,以便 git 仅在自定义工作区中自动检出一次。

我尝试了各种不同的风格:

这适用于声明性管道:

stage('blah') {
    node {
        label 'win'
        customWorkspace "c:\\w\\${JOB_NAME"
    }
    steps {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

但我找不到脚本管道的等效项:

pipeline {
    stage('stage1') {
        node('win-node') {
             // the git repository is checked out to ${env.WORKSPACE}, but it's unusable due to the path length issue
             ws("c:\\w\\${JOB_NAME}") {
                 // this switches the workspace, but doesn't clone the git repo again
                 body()
             }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想要这样的东西:

pipeline {
    stage('stage1') {
        node('win-node', ws="c:\\w\\${JOB_NAME}") {
            body()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

djp*_*ado 0

未经测试(特别是在节点内定义选项),但您可以尝试跳过默认签出并在更改工作区后执行此操作,如下所示:

pipeline {
    stage('stage1') {
        node('win-node') {
            options {
                skipDefaultCheckout true // prevent checkout to default workspace
            }
            ws("c:\\w\\${JOB_NAME}") {
                checkout scm // perform default checkout here
                body()
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)