在Jenkins Pipeline插件中获取工作区目录的绝对路径 [英] Get absolute path to workspace directory in Jenkins Pipeline plugin

查看:1714
本文介绍了在Jenkins Pipeline插件中获取工作区目录的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在对Jenkins Pipeline插件(以前称为Workflow插件)进行一些评估. 阅读文档后,我发现我目前无法使用检索工作空间路径 env.WORKSPACE:

I'm currently doing some evaluation on the Jenkins Pipeline plugin (formerly know as Workflow plugin). Reading the documentation I found out that I currently cannot retriev the workspace path using env.WORKSPACE:

以下变量当前在工作流脚本中不可用:

The following variables are currently unavailable inside a workflow script:

NODE_LABELS

NODE_LABELS

WORKSPACE

WORKSPACE

特定于SCM的变量,例如SVN_REVISION

SCM-specific variables such as SVN_REVISION

还有其他方法如何获取当前工作空间的绝对路径吗?我需要运行一些测试,该测试又获取一些参数(某些可执行文件的绝对路径). 我已经尝试在@NonCPS部分中使用new File("").absolutePath(),但是看起来非CPS的东西总是在主服务器上执行.

Is there any other way how to get the absolute path to the current workspace? I need this running some test which in turn gets some parameter (absolute path to some executable file). I already tried using new File("").absolutePath() inside a @NonCPS section but looks like the non-CPS stuff gets always executed on the master.

有人知道如何在不运行某些批处理脚本的情况下获取此路径吗?将批处理脚本存储到某个文件中,以后可以再次读取该文件?

Does anybody have a clue how to get this path without running some batch script which stores the path into some file which later on can be read in again?

推荐答案

Since version 2.5 of the Pipeline Nodes and Processes Plugin (a component of the Pipeline plugin, installed by default), the WORKSPACE environment variable is available again. This version was released on 2016-09-23, so it should be available on all up-to-date Jenkins instances.

这篇关于在Jenkins Pipeline插件中获取工作区目录的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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