我正在尝试捕获Jenkins启动脚本的输出,但我得到的只是一个空输出。
Jenkins的输出显示在终端
中#!/bin/bash
function sendNotificationOnSlack() {
curl -X POST ...
}
export -f sendNotificationOnSlack
java -Dhudson.DNSMultiCast.disabled=true -jar /usr/local/opt/jenkins/libexec/jenkins.war --httpPort=3999 | awk '/Jenkins is fully up and running/ {system("bash -c sendNotificationOnSlack")}'
我甚至尝试捕获TTY的输出,但显示为空
#!/bin/bash
currentTTY=$(tty)
echo $currentTTY
function sendNotificationOnSlack() {
curl -X POST ...
}
export -f sendNotificationOnSlack
java -Dhudson.DNSMultiCast.disabled=true -jar /usr/local/opt/jenkins/libexec/jenkins.war --httpPort=3999
tail -f $currentTTY | awk '/Jenkins is fully up and running/ {system("bash -c sendNotificationOnSlack")}'
我试图到处搜索但我找不到jenkins.log文件,有人有什么建议吗?
答案 0 :(得分:1)
创建以下groovy文件:$ JENKINS_HOME / init.groovy.d / extra-logging.groovy
重启Jenkins并检查目录$ JENKINS_HOME / logs /
import java.util.logging.ConsoleHandler
import java.util.logging.FileHandler
import java.util.logging.SimpleFormatter
import java.util.logging.LogManager
import jenkins.model.Jenkins
def logsDir = new File(Jenkins.instance.rootDir, "logs")
if(!logsDir.exists()){
println "--> creating log dir";
logsDir.mkdirs();
}
def loggerWinstone = LogManager.getLogManager().getLogger("");
FileHandler handlerWinstone = new FileHandler(logsDir.absolutePath + "/jenkins-winstone.log", 1024 * 1024, 10, true);
handlerWinstone.setFormatter(new SimpleFormatter());
loggerWinstone.addHandler (new ConsoleHandler());
loggerWinstone.addHandler(handlerWinstone);