How to set specific workspace folder for jenkins multibranch pipeline projects

the ws instruction sets the workspace for the commands inside it. for declarative pipelines, it's like this:

ws("C:\jenkins") {
  echo "awesome commands here instead of echo"
}

You can also call a script to build the customWorkspace to use:

# if the current branch is master, this helpfully sets your workspace to /tmp/ma
partOfBranch = sh(returnStdout: true, script: 'echo $BRANCH_NAME | sed -e "s/ster//g"')
path = "/tmp/${partOfBranch}"
sh "mkdir ${path}"
ws(path) {
  sh "pwd"
}

you can also set it globally by using the agent block (generally at the top of the pipeline block), by applying it to a node at that level:

pipeline {
  agent {
    node {
      label 'my-defined-label'
      customWorkspace '/some/other/path'
    }
  }
  stages {
    stage('Example Build') {
      steps {
        sh 'mvn -B clean verify'
      }
    }
  }
}

Another node instruction later on might override it. Search for customWorkspace at https://jenkins.io/doc/book/pipeline/syntax/. You can also it use it with the docker and dockerfile instructions.


Try this syntax instead:

pipeline {
    agent { 
        label {
            label 'EB_TEST_SEL'
            customWorkspace "/home/jenkins/workspace/ReleaseBuild/${BUILD_NUMBER}/"
        }
    }
}