我正在从事研发项目,我的想法是从 Jenkins
触发 shell 脚本
并将我得到的控制台输出写入放置的文件(文本文件)中在远程 Windows 服务器中。我尝试寻找选项,但没有一个有帮助。
是否有任何方法可以使用以下方法将 Jenkins
控制台输出写入位于远程服务器中的文本文件:
- 任何构建后操作或
- 任何外部 Jenkins 插件或
- 任何其他不同的方法
是否需要任何连接访问才能根据需要写入输出?请帮我想个办法。
最佳答案
我可以想出几种方法来实现这一目标:
运行 shell 命令时,将其重定向到文件:
echo scripting output > myScriptOutput.txt
然后将文件复制到远程文件共享:
copy myScriptOutput.txt \\server\share\subfolder
(可以在自由式或管道作业中完成)。
像上面一样重定向输出,然后归档工件,并使用 Publish Over...Plugins 之一将其复制到远程服务器(只能在自由式作业中完成)。
将远程服务器配置为 Jenkins 节点。然后,使用管道脚本,例如:
node("myBuildNodeNameOrLabel") { bat """echo scripting output > myScriptOutput.txt""" stash includes: 'myScriptOutput.txt', name: 'myScriptOutput' } node("myRemoteServerNodeNameOrLabel") { unstash 'myScriptOutput' // copy the file to another local folder outside the workspace bat """copy myScriptOutput.txt d:\\some\\other\\path""" }
与上面相同,但使用 Groovy 捕获脚本输出然后对其进行操作...
myOutput = bat returnStdout: true, script: """echo scripting output""" // now do whatever you want with the Groovy var myOutput...
Email-Ext插件可以通过电子邮件发送 Jenkins 的控制台输出。
关于shell - 将 Jenkins 控制台输出写入远程服务器中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46251801/