Jenkins Multibranch Pipeline工作区配置

Jenkins Multibranch Pipeline工作区配置

问题描述:

我反对 JENKINS-38706 .由于它已经开放了一段时间,所以我正在尝试解决它.​​

I'm bumping up against JENKINS-38706. And since its been open for a while, i'm trying to work around it.

我的问题是我正在运行多节点管道,其中一个节点是Windows从站,具有255个字符的路径限制.

My problem is that i'm running a multinode pipeline, with one of the nodes being a windows slave, with the 255 character path limitations.

因此,我尝试更改Windows从属阶段的工作区,而不是使用多分支管道使用的C:\ jenkins \ workspace \ job-branch-randomcharacters,而是尝试将其移至c :\ w \ job \ branch.

So, i'm trying to change the workspace for my windows slave stages, and instead of using C:\jenkins\workspace\job-branch-randomcharacters that the multibranch pipeline uses, i'm trying to move it to c:\w\job\branch.

它立即失败并显示:

Branch indexing
Obtained Jenkinsfile from 5bc168fcd5b3707048ad4bca4b5ef7478d759531
Running in Durability level: MAX_SURVIVABILITY
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 52: Too many arguments for map key "ws" @ line 52, column 15.
                    ws('C:\\w\\$JOB_NAME\\$BRANCH_NAME') {

我的Jenkinsfile代码段:

My Jenkinsfile snippet:

            stage ('Snapshot-WINDOWS') {
                agent {
                    node {
                        label 'win'
                        ws('C:\\w\\$JOB_NAME\\$BRANCH_NAME') {
                            body()
                        }
                    }
                }
                steps {
                    withMaven(
                        maven: 'Maven 3.5.3',
                        mavenSettingsConfig: 'settings'
                    ) {
                        bat 'mvn clean install'
                    }
                }
            }

要回答我自己的问题,而不是使用ws(),我需要使用customWorkspace,并且$ BRANCH_NAME会自动添加到多分支管道中.

To answer my own question, instead of using ws() i needed to use customWorkspace, and the $BRANCH_NAME gets automatically added with multibranch pipelines.

        stage ('Snapshot-WINDOWS') {
            agent {
                node {
                    label 'win'
                    customWorkspace 'C:\\w\\$JOB_NAME'
                }
            }
            steps {
                withMaven(
                    maven: 'Maven 3.5.3',
                    mavenSettingsConfig: 'settings'
                ) {
                    bat 'mvn clean install'
                }
            }
        }