【问题标题】:Jenkins pipeline : awx cli stdout詹金斯管道:awx cli标准输出
【发布时间】:2021-01-12 15:30:35
【问题描述】:

在我的 Jenkins 管道中,我启动了一个带有选项 --monitor 的 AWX 作业模板,主要目标是能够在 Jenkins 控制台中跟踪 AWX 中发生的事情。

 sh ("awx --conf.insecure --conf.host ${ansibleUrl} --conf.username ${ANSIBLE_USERNAME} --conf.password  ${ANSIBLE_PASSWORD} job_templates  launch --extra_vars @ansible_extra_vars_file.json --monitor  $ANSIBLE_JOB_TEMPLATE_ID  ")

类似的post about running an ansible playbook via a shell script in jenkins pipeline 已生成。但是,提出的解决方案并没有解决我的 pb 问题,因为我没有设置 returnStdout: true 。

仅当 Ansible 作业完成时,日志才会显示在 Jenkins 日志控制台中。

当我直接从 Jenkins slave 启动“awx job_templates launch”命令时,日志会实时显示在标准输出中。

如何在 Jenkins 日志控制台中实时更新标准输出?

【问题讨论】:

    标签: ansible jenkins-pipeline ansible-tower


    【解决方案1】:

    实际上,答案就在这篇关于Jenkins console output not in realtime的帖子中

    awxkit 包是用 Python 编写的,我只需要设置 PYTHONUNBUFFERED=1

    sh ("export PYTHONUNBUFFERED=1; awx --conf.insecure --conf.host ${ansibleUrl} --conf.username ${ANSIBLE_USERNAME} --conf.password  ${ANSIBLE_PASSWORD} job_templates  launch --extra_vars @ansible_extra_vars_file.json --monitor  $ANSIBLE_JOB_TEMPLATE_ID  ")
    

    这让我可以在我的 Jenkins 控制台中实时获取 AWX 日志。

    【讨论】:

    • 您可以添加选项“-f human”以避免将生成的 json 显示在 Jenkins 日志中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 2017-05-24
    相关资源
    最近更新 更多