Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

ansible - Jenkins pipeline : awx cli stdout

In my Jenkins pipeline, I launch a AWX job template with the option --monitor, the main goal being able to follow in Jenkins console what's going on in 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  ")

A similar post about running an ansible playbook via a shell script in jenkins pipeline had been made. However, the solution proposed does not solve my pb as I did not set returnStdout: true anyway.

The log is displayed in the Jenkins log console only when the Ansible job is completed.

When I launch the "awx job_templates launch" command directly from the Jenkins slave, the log is displayed in real time in the stdout.

How can I have the stdout being updated in real time in the Jenkins log console ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Actually, the answer was somehow in this post about Jenkins console output not in realtime

The awxkit package being coded in Python, I just needed to set 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  ")

This allowed me to obtain the AWX logs in real time in my Jenkins console.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...