1

Groovy、Closures 和 Jenkins 的新手。

我创建了一个种子工作:

def Job1 = 'FromTemplate-testJob'
job {
    name Job1
    steps {
       shell( "echo Hello > out5.txt" )
       shell( "/c echo custard > op4.txt")
    }
}

正如预期的那样,它成功创建了一个包含 2 个 shell 命令的子作业:

echo Hello > out5.txt
/c echo custard > op4.txt

但是,运行时,这个创建的作业显然运行成功,输出如下:

Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\jobs\FromTemplate-testJob\workspace
[workspace] $ C:\Windows\system32\cmd.exe -xe C:\Windows\TEMP\hudson3852539874278383422.sh
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Program Files (x86)\Jenkins\jobs\FromTemplate-testJob\workspace>[workspace] $ C:\Windows\system32\cmd.exe -xe C:\Windows\TEMP\hudson1697067517687695305.sh
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Program Files (x86)\Jenkins\jobs\FromTemplate-testJob\workspace>Finished: SUCCESS

但是,两个输出文件都没有在任何地方创建。shell 可执行文件定义为:

 C:\Windows\system32\cmd.exe

我不明白什么?

4

1 回答 1

3

shelldsl 命令被翻译为“Execute shell”构建步骤,通常用于类 Unix 系统。您必须改用batchFile dsl 命令,因此它将被转换为“执行 Windows 批处理命令”构建步骤,用于 Windows:

def Job1 = 'FromTemplate-testJob'
job {
    name Job1
    steps {
        batchFile( "echo Hello > out5.txt" )
        batchFile( "echo custard > op4.txt" )
    }
}
于 2015-07-28T11:05:50.560 回答