简体   繁体   中英

Jenkins Multibranch Pipeline workspace configuration

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

You forgot to declare the workspace. Example:

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

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

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