更新时间:2023-12-05 13:51:58
每个版本都有一个工作区,因此您需要首先找到所需的项目。 (在Jenkins中也使用术语job和project,在API中也是可以互换的。)
然后,你可以交叉手指,只需打电话 getWorkspace()
,这已弃用(请参阅 JavaDoc 详情)。
或者你可以找到一个特定的构建(例如最后一个),它可以通过工作空间 c $ c $> getWorkspace()方法,因为它在 AbstractBuild
类中定义。
示例代码:
Jenkins.instance.getJob('< job-name>')。lastBuild.workspace;
I have a question very similar to this: Reading file from Workspace in Jenkins with Groovy script
However I need to read the file from a System Groovy script so the solution of using Text-finder or the Groovy PostBuild plugin will not work.
How can I get the workspace path from a system groovy script? I have tried the following:
System.getenv('WORKSPACE')
System.getProperty("WORKSPACE")
build.buildVariableResolver.resolve("WORKSPACE")
Thanks!
Each build has a workspace, so you need to find the desired project first. (The terms "job" and "project" are used rather interchangeable in Jenkins - also in the API.)
After that, you can either cross your fingers and just call getWorkspace()
, which is deprecated (see JavaDoc for details).
Or you can find a specific build (e.g. the last), which can give you the workspace used for that specific build via the getWorkspace()
method as it is defined in the AbstractBuild
class.
Example code:
Jenkins.instance.getJob('<job-name>').lastBuild.workspace;