<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 4, 2021 at 10:55 AM Aaron Conole <<a href="mailto:aconole@redhat.com">aconole@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Salvatore Daniele <<a href="mailto:sdaniele@redhat.com" target="_blank">sdaniele@redhat.com</a>> writes:<br>
<br>
> A github job can fail multiple steps within a single job.<br>
> The current implementation fails to pull logs when handed a<br>
> job with multiple failed steps.<br>
><br>
> This patch generates logs for each step of each job.<br>
><br>
> Signed-off-by: Salvatore Daniele <<a href="mailto:sdaniele@redhat.com" target="_blank">sdaniele@redhat.com</a>><br>
> ---<br>
> github_get_logs.sh | 13 +++++++------<br>
> 1 file changed, 7 insertions(+), 6 deletions(-)<br>
><br>
> diff --git a/github_get_logs.sh b/github_get_logs.sh<br>
> index 2f6cc9c..99b60a1 100755<br>
> --- a/github_get_logs.sh<br>
> +++ b/github_get_logs.sh<br>
> @@ -97,28 +97,29 @@ print_errored_logs_for_commit () {<br>
> <br>
> # Print out which jobs failed<br>
> echo "-----------------------Summary of failed steps-----------------------"<br>
> - echo "$jobs_results" | jq -r ".[].name" | while read -r job; do<br>
> - echo "\"$job\" failed at step \"$(echo "$jobs_results" | jq -r ".[] | \<br>
> - select(.name==\"$job\") | .<a href="http://failed_step.name" rel="noreferrer" target="_blank">failed_step.name</a>")\""<br>
> + echo "$jobs_results" | jq -r ".[] | .name, .<a href="http://failed_step.name" rel="noreferrer" target="_blank">failed_step.name</a> " | while \<br>
> + read -r job && read -r step; do<br>
<br>
Why this:<br>
<br>
read .. && read ..<br>
<br>
Can't it just be:<br>
<br>
while IFS=',' read -r job step; do<br>
...<br>
done<br>
<br>
Did I miss something?<br></blockquote><div><br></div><div>So perhaps I am using IFS wrong. I did try a number of things like that, </div><div><br></div><div>E.g.</div><div>jobs_results='[{<br> "name": "e2e (control-plane, true, true, true, ipv4, IPv4, true, false)",<br> "failed_step": {<br> "name": "Run Tests",<br> "conclusion": "failure",<br> "number": 11<br> }<br>}, {<br> "name": "e2e (control-plane, true, true, true, ipv4, IPv4, true, false)",<br> "failed_step": {<br> "name": "Generate Test Report",<br> "conclusion": "failure",<br> "number": 13<br> }<br>}]'</div><div><br></div><div>echo "$jobs_results" | jq -r ".[] | .name, .<a href="http://failed_step.name">failed_step.name</a> " | while IFS=',' read -r job step; do<br> echo "job = \"$job\" and step = \"$step\""<br>done<br></div><div><br></div><div>Yields the output:</div><div><br></div><div>job = e2e (control-plane and step = true, true, true, ipv4, IPv4, true, false)<br>job = Run Tests and step = <br>job = e2e (control-plane and step = true, true, true, ipv4, IPv4, true, false)<br>job = Generate Test Report and step = <br></div><div><br></div><div>while IFS=$'\n' read -r job step; do<br></div><div><br></div><div>Yields</div><div><br></div><div>job = "e2e (control-plane, true, true, true, ipv4, IPv4, true, false)" and step = ""<br>job = "Run Tests" and step = ""<br>job = "e2e (control-plane, true, true, true, ipv4, IPv4, true, false)" and step = ""<br>job = "Generate Test Report" and step = ""<br></div><div> </div><div>There must be some way to make it work since there is a similar loop to what you're describing in "ci_mon" but I was </div><div>certainly struggling to find a cleaner solution that just multiple read statements. </div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> + echo "\"$job\" failed at step $step"<br>
> done<br>
> echo "----------------------End summary of failed steps--------------------"<br>
> <br>
> echo ""<br>
> echo "-------------------------------BEGIN LOGS----------------------------"<br>
> spacing=0<br>
> +<br>
> # Print out logs for failed jobs<br>
> - echo "$jobs_results" | jq -r ".[].name" | while read -r job; do<br>
> + echo "$jobs_results" | jq -r ".[] | .name, .<a href="http://failed_step.name" rel="noreferrer" target="_blank">failed_step.name</a>, .failed_step.number" | while \<br>
> + read -r job && read -r step && read -r log_number; do<br>
> +<br>
<br>
Same as above.<br>
<br>
Do we still have a 2-job issue with this? Can you send a link to an<br>
example job?<br></blockquote><div><br></div><div>Yes, this was the example I was working on when the bug came up [1]. Michael pointed out that the ovn-kubernetes workflow often has two steps within the same job (specifically run tests and generate test report) fail, which was causing the following cat statement to fail, since $step and $log_number would be equal to:</div><div><br></div><div>"Run Tests</div><div>Generate Test Report"</div><div><br></div><div>"11</div><div>13"</div><div><br></div><div>[1] <a href="https://github.com/ovsrobot/ovn/runs/3137144963?check_suite_focus=true">https://github.com/ovsrobot/ovn/runs/3137144963?check_suite_focus=true</a></div><div><a href="https://patchwork.ozlabs.org/api/patches/1508829/">https://patchwork.ozlabs.org/api/patches/1508829/</a><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> if [ ! "$spacing" -eq "0" ]<br>
> then<br>
> echo -ne "\n\n\n\n"<br>
> fi<br>
> <br>
> - step="\"$(echo "$jobs_results" | jq -r ".[] | select(.name==\"$job\") | .<a href="http://failed_step.name" rel="noreferrer" target="_blank">failed_step.name</a>")\""<br>
> echo "####################################################################################"<br>
> echo "#### [Begin job log] \"$job\" at step $step"<br>
> echo "####################################################################################"<br>
> <br>
> - log_number=$(echo "$jobs_results" | jq ".[] | select(.name==\"$job\") | .failed_step.number")<br>
> cat "build_logs_series_$series_id/$job/$log_number"_* | tail -n 25 | cut -d' ' -f2- | sed 's/\r$//'<br>
> <br>
> echo "####################################################################################"<br>
<br>
</blockquote></div></div>