Mic*_*ael 10 jenkins jenkins-pipeline
我有一个外部工具,应该在我的一个jenkins工作中调用build-step.不幸的是,这个工具在引用命令方面存在一些问题,以避免调用路径中的空格问题.
詹金斯安装在C:\Program Files (x86)\Jenkins.因此,我在使用jenkins调用外部工具时遇到了麻烦.
我尝试的是在Jenkins-> configuration中设置"Workspace Root Directory" C:\jenkins_workspace以避免任何空格.这适用于Freestyle项目,但我的Multibranch管道项目仍在检查和构建C:\Program Files (x86)\Jenkins\workspace.
一种解决方案是将整个jenkins装置移动到例如C:\jenkins.这个我想避免.是否有正确的方法告诉Jenkins Pipeline工作也使用"工作区根目录"?
谢谢你的帮助
bur*_*ttk 23
该ws指令为其中的命令设置工作空间.对于声明性管道,它是这样的:
ws("C:\jenkins") {
echo "awesome commands here instead of echo"
}
Run Code Online (Sandbox Code Playgroud)
您还可以调用脚本来构建要使用的customWorkspace:
# 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"
}
Run Code Online (Sandbox Code Playgroud)
你也可以使用agent块(通常在块的顶部pipeline)通过将其应用于node该级别来全局设置它:
pipeline {
agent {
node {
label 'my-defined-label'
customWorkspace '/some/other/path'
}
}
stages {
stage('Example Build') {
steps {
sh 'mvn -B clean verify'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
node稍后的另一条指令可能会覆盖它.搜索customWorkspace在https://jenkins.io/doc/book/pipeline/syntax/.您也可以将它与使用docker和dockerfile说明.