问题描述
这是我的Jenkins 2.x管道:
Here's my Jenkins 2.x pipeline:
node ('master'){
stage 'Checkout'
checkout scm
stage "Build Pex"
sh('build.sh')
}
当我运行此管道时,签出将代码按预期方式放入工作区中,但是与其期望不在工作区/中找到脚本(它确实在那里!),而是在一个不相关的目录中查找:workspace @ tmp/durable -d812f509.
When I run this pipeline the checkout puts the code into to the workspace as expected, however instead of expecting to find the script in workspace/ (it's really there!), it looks in an unrelated directory: workspace@tmp/durable-d812f509.
Entering stage Build Pex
Proceeding
[Pipeline] sh
[workspace] Running shell script
+ build.sh
/home/conmonsysdev/deployments/jenkins_ci_2016_interns/jenkins_home/jobs/pex/branches/master/workspace@tmp/durable-d812f509/script.sh: line 2: build.sh: command not found
如何修改此Jenkinsfile,以便在与签出项目源代码的目录完全相同的目录中执行build.sh?
How do I modify this Jenkinsfile so that build.sh is executed in the exact same directory as where I checked out the project source code?
推荐答案
您可以将操作包含在dir
块中.
You can enclose your actions in dir
block.
checkout scm
stage "Build Pex"
dir ('your new directory') {
sh('build.sh')
}
...
your new directory
是您实际目录的占位符.默认情况下,它是工作空间的相对路径.如果您确定代理中存在绝对路径,则可以定义绝对路径.
your new directory
is place holder your actual directory. By default it is a relative path to workspace. You can define absolute path, if you are sure this is present on the agent.
这篇关于如何让Jenkins 2.0在与结帐相同的目录中执行sh命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!