How to set specific workspace folder for projects with multiple jenkins chips
I have an external tool that should be named as a build step in one of my jenkins jobs. Unfortunately this tool has some issues with quoting commands to avoid issues with spaces in the called path.
Jenkins is set to C:\Program Files (x86)\Jenkins
. So I'm having trouble with jenkins calling an external tool.
I tried to set "Workspace Root" in Jenkins-> config C:\jenkins_workspace
to avoid any whitespace. This works for Freestyle projects, but my Multibranch Pipeline Project is still being tested and built under C:\Program Files (x86)\Jenkins\workspace
.
One solution would be to move the entire jenkins installation, for example C:\jenkins
. I would like to avoid this. Is there a correct way to just tell Jenkins Pipeline jobs to use the "Root Workspace"?
Thanks for any help
source to share
The instruction ws
sets up a workspace for the commands within it. for declarative pipelines it is like this:
ws("C:\jenkins") {
echo "awesome commands here instead of echo"
}
You can also call a script to create a 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 using a block agent
(usually at the top of a block pipeline
), applying it to node
at this level:
pipeline {
agent {
node {
label 'my-defined-label'
customWorkspace '/some/other/path'
}
}
stages {
stage('Example Build') {
steps {
sh 'mvn -B clean verify'
}
}
}
}
Another instruction node
can later override it. Find the customWorkspace
address https://jenkins.io/doc/book/pipeline/syntax/ . You can also use it with instructions docker
and dockerfile
.
source to share