我想有一个post-build钩子或者类似的,所以我可以拥有与IRC插件相同的输出,但是将它提供给脚本.除了实际构建状态之外,我能够获得所有信息.这不起作用,既不作为"后构建脚本","后构建任务","参数化触发器"aso.
这可能是一些非常丑陋的变通方法,但我想问一下,万一有人有更好的选择...没有写我自己的插件.
在我的gradle文件中,我定义了以下任务:
task text_example <<
{
//?!? commandLine ''
println 'Fam Flinstone'
}
Run Code Online (Sandbox Code Playgroud)
我想在这个任务中加入一些命令行.我怎样才能做到这一点 ?
我正在使用图书馆在Google Play中自动发布.我的项目基于Product Flavors,我需要通过命令行传递终端命令行,用于我的每一个口味.所以我想在test_example
任务中传递所有命令行.
以下代码被卡住(我认为是阻塞I/O)多次(工作一段时间).
def static executeCurlCommand(URL){
def url = "curl " + URL;
def proc = url.execute();
def output = proc.in.text;
return output;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我将代码更改为
def static executeCurlCommand(URL){
def url = "curl " + URL;
def proc = url.execute();
def outputStream = new StringBuffer();
proc.waitForProcessOutput(outputStream, System.err)
return outputStream.toString();
}
Run Code Online (Sandbox Code Playgroud)
它每次都很好用.我无法理解为什么第一种方式即通过proc.in.text
挂起一段时间来输入?当我在Windows和cygwin上尝试它时,看起来不是特定于环境的问题.
为了测试/运行上面的方法,我尝试过 -
public static void main(def args){
def url = 'http://mail.google.com';
println("Output : " + executeCurlCommand(url));
}
Run Code Online (Sandbox Code Playgroud)
我在SO上看到了多个问题,并且都提供了第二种方法.虽然它运作良好但我希望我知道第一种方法有什么问题?有没有人以前遇到过这种情况?
我想在Uno-Choice动态参考参数中调用shell脚本并执行一些操作(创建一些文件并从被调用的shell脚本调用一些其他shell脚本).
截至目前,我能够调用shell脚本并捕获一些文件,但我无法创建新文件或从中调用另一个shell脚本.
def sout = new StringBuffer(), serr = new StringBuffer()
// 1)
def proc ='cat /home/path/to/file'.execute()
//display contents of file
// 2)
def proc="sh /home/path/to/shell/script.sh".execute()
//to call a shell script but the above dosent work if I echo some contents
//into some file.
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
return sout.tokenize()
Run Code Online (Sandbox Code Playgroud)
例如: - script.sh
如果我添加线
echo "hello world" > test
Run Code Online (Sandbox Code Playgroud)
然后没有创建测试文件
为了更多的理解:
我正在使用Jenkins在linux机器上启动脚本.
当我运行这个手动的服务器上,它的工作原理:
/bin/bash -c '/some/script MyProduct SomeBranch'
当我用groovy 运行它时,它不起作用.
我得到了同样的错误,好像我没有传递"-c"选项,所以不知何故"-c"不起作用.
这是我的代码:
branchName = "SomeBranch"
configName = "release"
println "Building for branch "+branchName+" and configuration "+configName
def chkbranch = { String product, String branch -> mkcmd( product, branch ) }
private def mkcmd ( String product, String branch ) {
// Build the command string to run
def cmd = "/bin/bash -c '/some/script "+product+" "+branch+"'"
def sout = new …
Run Code Online (Sandbox Code Playgroud) 我需要编写一个常规脚本,即执行外部程序并将该程序的输出打印到控制台。
这是相关的代码片段:
def pmdCommand = "${scriptDir}/run.sh pmd -d ${filesToAnalyse}"
def sout = new StringBuffer()
def serr = new StringBuffer()
def process = pmdCommand.execute()
process.consumeProcessOutput(sout, serr)
process.waitFor()
if (process.exitValue() !=0 ) {
System.err << serr.toString()
System.exit(-1)
}
else {
System.out << sout.toString()
System.exit(0)
}
Run Code Online (Sandbox Code Playgroud)
我在Java中做了类似的事情,但我无法将其转换为groovy。
StringBuffer output = new StringBuffer();
String s = null;
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println(s); …
Run Code Online (Sandbox Code Playgroud) 我刚开始学习DevOps,有一个疑问。这可能是非常基本的,所以请不要介意。
设置:Jenkins、GIT、Groovy、Java 安装在单个 Windows 服务器上。
我的目标是编写一个 Groovy 脚本,它将执行以下操作: 1. 执行 GIT 命令(在本地 GIT 存储库上)以提取一些数据(结果)。2. 根据上述结果采取进一步行动。
查询:如何在 Groovy 脚本中执行 GIT 命令?都需要什么?如果有人可以分享一个示例基本脚本,那就太好了。