问题描述
因此,在下面,我附上了Jenkins的管道代码. runansible.sh脚本接受给定的参数,然后继续基于paramMode
值运行ansible剧本.在终端中启动shell脚本时,我会实时获取ansible剧本的输出,但是当使用Jenkins管道时,我只是在echo阶段获得了加载齿轮.在整个剧本完成之前,我没有得到任何回声输出,然后立即将其全部吐出.我需要能够像在终端中一样从剧本中获得实时输出,以便在构建过程中可以监视进度.我需要怎么做才能获得实时输出?
So below I have attached my pipeline code for Jenkins. The runansible.sh script takes in the parameters given and then proceeds to run an ansible playbook based on the paramMode
value. When kicking off the shell script in a terminal I get realtime output of the ansible playbook running, but when using the Jenkins pipeline I just get the loading cogwheel during the echo stage. I do not get any echo output until the whole playbook has completed and then it spits it out all at once. I need to be able to have live output from the playbook like I do in a terminal so the progress can be monitored as the build is building. What do I need to do to get realtime output?
def paramMode = "${params.mode}"
def paramClientCode = "${params.client_code}"
def paramPrevCodeDropID = "${params.prev_code_drop_id}"
def paramCodeDropID = "${params.code_drop_id}"
def paramReleaseID = "${params.release_id}"
def paramConfigZipVer = "${params.config_zip_ver}"
def paramEmailIDs = "${params.email_ids}"
node {
stage('one-click') {
node ('nodeName') {
git url: "gitURL", branch: "runParallel", credentialsId: "stash_id"
echo sh (returnStdout: true, script: """
./runansible.sh ${paramMode} -h ${paramClientCode} -c ${paramCodeDropID} -r ${paramReleaseID} -v ${paramConfigZipVer} -e ${paramEmailIDs} -p ${paramPrevCodeDropID}
""")
}
}
}
推荐答案
我认为您想要的已经是sh
的默认行为,但是您已经通过使用returnStdout: true
禁用了它.这将导致捕获输出并返回而不是打印输出.然后用echo
打印.
I think what you want is already the default behavior of sh
, but you have disabled it by using returnStdout: true
. This causes the output to be captured and returned, instead of printed. Then you print it with echo
.
来自文档> :
如果选中,则任务的标准输出为 作为字符串作为步长值返回,而不是打印到 构建日志. (如果有标准错误,则仍会打印到 日志.)
If checked, standard output from the task is returned as the step value as a String, rather than being printed to the build log. (Standard error, if any, will still be printed to the log.)
所以不要尝试sh (...)
而不是sh (...)
这篇关于当通过Jenkins管道中的shell脚本运行ansible剧本时,回声输出将被缓冲并且不会实时显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!