Jenkins Multibranch Pipeline workspace configuration

╄→гoц情女王★ 提交于 2019-12-13 05:16:16

问题


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

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.

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.

It immediately fails with:

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') {

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'
                    }
                }
            }

回答1:


You forgot to declare the workspace. Example:

def wsDir = "/some/path/${env.BRANCH_NAME}"
ws (wsDir) {
// some block
}



回答2:


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'
                }
            }
        }


来源:https://stackoverflow.com/questions/52525409/jenkins-multibranch-pipeline-workspace-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!