Skip to main content

Re-running workflows and jobs

You can re-run a workflow run, all failed jobs in a workflow run, or specific jobs in a workflow run up to 30 days after its initial run.

谁可以使用此功能?

People with write permissions to a repository can re-run workflows in the repository.

Tool navigation

注意

GitHub Enterprise Server 目前不支持 GitHub 托管的运行器。 可以在 GitHub public roadmap 上查看有关未来支持计划的更多信息。

About re-running workflows and jobs

Re-running a workflow or jobs in a workflow uses the same GITHUB_SHA (commit SHA) and GITHUB_REF (Git ref) of the original event that triggered the workflow run. The workflow will use the privileges of the actor who initially triggered the workflow, not the privileges of the actor who initiated the re-run. You can re-run a workflow or jobs in a workflow for up to 30 days after the initial run. You cannot re-run jobs in a workflow once its logs have passed their retention limits. For more information, see Usage limits, billing, and administration. When you re-run a workflow or jobs in a workflow, you can enable debug logging for the re-run. This will enable runner diagnostic logging and step debug logging for the re-run. For more information about debug logging, see Enabling debug logging

Re-running all the jobs in a workflow

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库名称下,单击 “操作”。

    “github/docs”存储库的选项卡的屏幕截图。 “操作”选项卡以橙色边框突出显示。

  3. 在左侧边栏中,单击您想要查看的工作流程。

    “操作”选项卡的左侧边栏的屏幕截图。工作流“CodeQL”以深橙色标出。

  4. 在工作流运行列表中,单击运行的名称以查看工作流运行摘要。

  5. In the upper-right corner of the workflow, re-run jobs.

    • If any jobs failed, select the Re-run jobs dropdown menu and click Re-run all jobs.

    • If no jobs failed, click Re-run all jobs.

  6. (可选)若要为重新运行启用运行程序诊断日志记录和步骤调试日志记录,请选择“启用调试日志记录”。

  7. 单击“重新运行作业****”。

注意

若要详细了解 GitHub CLI,请参阅“关于 GitHub CLI”。

To re-run a failed workflow run, use the run rerun subcommand. Replace run-id with the ID of the failed run that you want to re-run. If you don't specify a run-id, GitHub CLI returns an interactive menu for you to choose a recent failed run.

gh run rerun RUN_ID

若要为重新运行启用运行器诊断日志记录和单步调试日志记录,请使用 --debug 标志。

gh run rerun RUN_ID --debug

To view the progress of the workflow run, use the run watch subcommand and select the run from the interactive list.

gh run watch

Re-running failed jobs in a workflow

If any jobs in a workflow run failed, you can re-run just the jobs that failed. When you re-run failed jobs in a workflow, a new workflow run will start for all failed jobs and their dependents. Any outputs for any successful jobs in the previous workflow run will be used for the re-run. Any artifacts that were created in the initial run will be available in the re-run. Any deployment protection rules that passed in the previous run will automatically pass in the re-run.

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库名称下,单击 “操作”。

    “github/docs”存储库的选项卡的屏幕截图。 “操作”选项卡以橙色边框突出显示。

  3. 在左侧边栏中,单击您想要查看的工作流程。

    “操作”选项卡的左侧边栏的屏幕截图。工作流“CodeQL”以深橙色标出。

  4. 在工作流运行列表中,单击运行的名称以查看工作流运行摘要。

  5. In the upper-right corner of the workflow, select the Re-run jobs dropdown menu, and click Re-run failed jobs.

  6. (可选)若要为重新运行启用运行程序诊断日志记录和步骤调试日志记录,请选择“启用调试日志记录”。

  7. 单击“重新运行作业****”。

To re-run failed jobs in a workflow run, use the run rerun subcommand with the --failed flag. Replace run-id with the ID of the run for which you want to re-run failed jobs. If you don't specify a run-id, GitHub CLI returns an interactive menu for you to choose a recent failed run.

gh run rerun RUN_ID --failed

若要为重新运行启用运行器诊断日志记录和单步调试日志记录,请使用 --debug 标志。

gh run rerun RUN_ID --failed --debug

Re-running a specific job in a workflow

When you re-run a specific job in a workflow, a new workflow run will start for the job and any dependents. Any outputs for any other jobs in the previous workflow run will be used for the re-run. Any artifacts that were created in the initial run will be available in the re-run. Any deployment protection rules that passed in the previous run will automatically pass in the re-run.

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库名称下,单击 “操作”。

    “github/docs”存储库的选项卡的屏幕截图。 “操作”选项卡以橙色边框突出显示。

  3. 在左侧边栏中,单击您想要查看的工作流程。

    “操作”选项卡的左侧边栏的屏幕截图。工作流“CodeQL”以深橙色标出。

  4. 在工作流运行列表中,单击运行的名称以查看工作流运行摘要。

  5. Under the "Jobs" section of the left sidebar, next to the job that you want to re-run, click .

  6. (可选)若要为重新运行启用运行程序诊断日志记录和步骤调试日志记录,请选择“启用调试日志记录”。

  7. 单击“重新运行作业****”。

To re-run a specific job in a workflow run, use the run rerun subcommand with the --job flag. Replace job-id with the ID of the job that you want to re-run.

gh run rerun --job JOB_ID

若要为重新运行启用运行器诊断日志记录和单步调试日志记录,请使用 --debug 标志。

gh run rerun --job JOB_ID --debug

Re-running workflows and jobs with reusable workflows

可使用 SHA、发布标记或分支名称引用公共存储库中的可重用工作流。 有关详细信息,请参阅“Reusing workflows”。

重新运行使用可重用工作流且引用不是 SHA 的工作流时,有一些行为需要注意:

  • 重新运行工作流中的所有作业时将使用指定引用中的可重用工作流。 有关重新运行工作流中所有作业的详细信息,请参阅 Re-running workflows and jobs
  • 重新运行失败的作业或工作流中的特定作业时将使用第一次尝试的同一提交 SHA 中的可重用工作流。 有关重新运行工作流中失败作业的详细信息,请参阅 Re-running workflows and jobs。 有关重新运行工作流中特定作业的详细信息,请参阅 Re-running workflows and jobs

Reviewing previous workflow runs

You can view the results from your previous attempts at running a workflow. You can also view previous workflow runs using the API. For more information, see 工作流运行的 REST API 终结点.

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库名称下,单击 “操作”。

    “github/docs”存储库的选项卡的屏幕截图。 “操作”选项卡以橙色边框突出显示。

  3. 在左侧边栏中,单击您想要查看的工作流程。

    “操作”选项卡的左侧边栏的屏幕截图。工作流“CodeQL”以深橙色标出。

  4. 在工作流运行列表中,单击运行的名称以查看工作流运行摘要。

  5. To the right of the run name, select the Latest dropdown menu and click a previous run attempt.