我的 github actions 工作流程管道在过去 25 天内运行了 80 多次。
它通过从数据库中选择主机名来修补主机上的 JDK。主机名记录在 github 工作流程运行日志/输出中。
我现在面临的挑战是给定一个主机名“myhost17”,我如何找到 github 工作流程运行 URL,以便我可以回去检查输出。
打开所有 80 多个管道运行非常乏味,我正在寻找更好的问题解决方案。
下面的脚本帮助我获取特定工作流程每次运行的 URL,但每次运行的日志均未显示。
#!/bin/bash
# Run the command and store the output in a variable
output=$(curl -u megithubuser:<github-token> -s "https://api.github.com/repos/mybank/heal/actions/workflows/java-patching.yml/runs" | grep -i ' "url": ' | grep -i runs | awk -F'"' '{print $4}')
# Loop over each URL in the output
while IFS= read -r url; do
# Append /logs to the URL
url_with_logs="${url}/logs"
# Perform actions on each URL
echo "Processing URL: \"$url_with_logs\""
curl -u megithubuser:<github-token> -s $url_with_logs
done <<< "$output"
输出:
Processing URL: "https://api.github.com/repos/mybank/heal/actions/runs/8934576962/logs"
curl -u megithubuser:<github-token> -s "https://api.github.com/repos/mybank/heal/actions/runs/8934576962/logs"
Processing URL: "https://api.github.com/repos/mybank/heal/actions/runs/8934231577/logs"
curl -u megithubuser:<github-token> -s "https://api.github.com/repos/mybank/heal/actions/runs/8934231577/logs"
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/actions/workflow-runs#download-workflow-run-logs"
}
请推荐。
要下载 GitHub 工作流日志,请执行以下操作:
列出工作流程运行 ID
curl --header "授权:持有者 GITHUB_TOKEN" --request GET "https://GITHUB_SERVER/repos/OWNER/REPO/actions/workflows/WORKFLOW/runs" | jq --raw-output '.workflow_runs[] | jq --raw-output '.workflow_runs[] | .id'
对于每个运行 ID,下载日志
curl --header“授权:承载GITHUB_TOKEN”--location --header“接受:application/vnd.github+json”--request GET“https://GITHUB_SERVER/repos/OWNER/REPO/actions/runs/RUN_ID /logs" --输出运行日志.zip