使用System groovy脚本从Jenkins工作区中读取文件 [英] Read file from Jenkins workspace with System groovy script

查看:933
本文介绍了使用System groovy脚本从Jenkins工作区中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似这样的问题:阅读文件来自Jenkins的Workspace with Groovy脚本



然而,我需要从System Groovy脚本中读取文件,以便使用Text-finder或Groovy PostBuild插件将无法工作。



如何从系统groovy脚本获取工作区路径?我尝试了以下方法:

pre code System.getenv('WORKSPACE')
System.getProperty(WORKSPACE)
build.buildVariableResolver.resolve(WORKSPACE)

谢谢!

解决方案

每个版本都有一个工作区,因此您需要首先找到所需的项目。 (在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;

这篇关于使用System groovy脚本从Jenkins工作区中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆