How to obtain the folder where the Pipeline Jenkinsfile is checked out (Jenkins)

て烟熏妆下的殇ゞ 提交于 2019-12-25 07:13:39

问题


We're having a big project (in terms of size), that we're trying to build using a Jenkinsfile that is checked inside the project itself.

In order to conserve disk space and build times we try to minimize the number of copies, so what we would want is to use the folder where the Jenkinsfile is checked out, since that is already a repo fully cloned.

Manually investigating, I've seen that there is a workspace@script folder created inside the job's folder. That is folder path that I would like to obtain.

I would have expected pwd() to do the trick, but for some reason that works only inside nodes, resolving the path to that folder.

stage "Build"

def scriptWorkspace=??

node {
  sh """
    TERM=xterm ls --color /etc
    set

    docker run ... -v ${scriptWorkspace}:/mercurial-repository ...
  """
}

回答1:


Pending an implementation of JENKINS-33273 for the SCM you are using (Mercurial in this case I suppose? would require use of the “caching” feature in that plugin), Jenkinsfile is always checked out on a private workspace on the master node, not available to the script itself.



来源:https://stackoverflow.com/questions/37675194/how-to-obtain-the-folder-where-the-pipeline-jenkinsfile-is-checked-out-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!