且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Jenkins Workflow 插件中获取 SVN 修订号?

更新时间:2023-02-12 19:24:02

No such file or directory 错误的意思就是:Subversion is not installed on your build slave.

The No such file or directory error means just what it says: Subversion is not installed on your build slave.

您似乎已经明白了,并尝试通过使用 tool 安装 Subversion 来解决它.但是 Jenkins Subversion 插件没有 Subversion 的工具定义;它总是使用 SVNKit,一个进程内 (Java) 库.所以这行不通.

You seem to have gotten that, and tried to work around it by using tool to install Subversion. But the Jenkins Subversion plugin has no tool definition for Subversion; it always uses SVNKit, an in-process (Java) library. So this cannot work.

(顺便说一下,Mercurial 插件总是运行 hg 可执行文件,Git 插件可以使用 git 可执行文件或嵌入的 JGit 库.两者都让你定义工具安装,但定义特殊(自动)安装程序,所以它们对这种情况没有多大帮助.你也可以运行 sh 'sudo apt-get install颠覆'.)

(By the way the Mercurial plugin always runs the hg executable, and the Git plugin can use either a git executable or the embedded JGit library. Both let you define tool installations, but do not define special (automatic) installers, so they would not be of much help for this kind of situation. You would do as well running sh 'sudo apt-get install subversion'.)

假设您安装了 Subversion,以便 svn 在您的 $PATH 中,下一个问题是使用 String.execute() 从GDK 通常也不会在工作流中工作.那是因为流程脚本是在 Jenkins 主进程内部运行的,而不是在从属进程上运行的.您必须使用 sh 步骤(或 Windows 从站上的 bat)来运行外部命令.至于从他们那里获取输出,JENKINS-26133 描述了当前的成语.

Assuming you install Subversion so that svn is in your $PATH, the next issue is that using String.execute() from the GDK will not generally work in a Workflow either. That is because the flow script is run inside the Jenkins master process, not on the slave. You must use the sh step (or bat on a Windows slave) to run external commands. As to getting output back from them, JENKINS-26133 describes the current idiom.

String.find 目前无法工作:JENKINS-26481.改用 Java 平台方法,或者使用任何不使用闭包的方法.

String.find from the JDK will not currently work: JENKINS-26481. Use Java Platform methods instead, or just anything not taking a closure.

出于类似于为什么 String.execute() 不合适的原因,System.getenv 无法为工作流构建定义环境变量":这将只加载 Jenkins 主进程上设置的环境变量,在 Jenkins 启动时固定.您正在考虑的变量仅在分叉进程(sh/bat)上设置;或者您可以使用 env.VARIABLE 语法从 Groovy 访问它们.

For reasons similar to why String.execute() is inappropriate, System.getenv will not work to get "environment variables" defined for the workflow build: this will only load environment variables set on the Jenkins master process, fixed at Jenkins startup time. The variables you are thinking of are set only on forked processes (sh/bat); or you can access them from Groovy using env.VARIABLE syntax.

您真正想要开始的是直接访问 SVN_REVISION 而不必自己运行 svn info.这被跟踪为 JENKINS-26100.

What you really wanted to begin with was direct access to SVN_REVISION without having to run svn info yourself. This is tracked as JENKINS-26100.