admin管理员组文章数量:1123781
Usually, in a shell script one can redirect stdout and stderr to a logfile using:
<command_to_run> > <log_file> 2>& 1
Example: ps -efww > /tmp/processes.log 2>&1
However, I want to do the same in a Jenkins pipeline via groovy script.
node('tool'){
def failedMachines = []
def machinesToCheck = [
"machine1",
"machine2"
]
String processCheckCmd = "git clone <repository>"
stage("Check processes") {
parallelRunnable = [:]
for(int i = 0; i < machinesToCheck.size(); i++){
def tmpMachine = machinesToCheck[i]
parallelRunnable[tmpMachine] = {
node(nodetmpMachinename){
try {
sh """
echo "Running: ${processCheckCmd}"
${processCheckCmd} > "${nodetmpMachinename}.log" 2>&1
"""
archiveArtifacts artifacts: "*.log", allowEmptyArchive: true
} catch(e){
echo "Failed to clone on ${nodetmpMachinename}"
failedMachines.add(nodetmpMachinename)
}
}
}
}
parallel parallelRunnable
}
stage('Status'){
if(failedMachines){
error("Failed to clone on some machines: ${failedMachines}")
}
echo "Clone complete"
}
}
However, if the command fails to run then it does not log to the file. I do get the logs for successful run. Any pointers as to what the issue is here?
本文标签:
版权声明:本文标题:logging - Groovy invoke a shell script and redirect stdout and stderr to logfile and Jenkins console - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736593563a1945114.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论