创建 Azure 自动化 RunbookCreate an Azure Automation runbook

Azure 自动化 Runbook 可以通过 Azure 创建。Azure Automation runbooks can be created through Azure. 此方法提供一个基于浏览器的用户界面,用于创建自动化 Runbook。This method provides a browser-based user interface for creating Automation runbooks. 本快速入门介绍如何创建、编辑、测试和发布自动化 PowerShell Runbook。In this quickstart you walk through creating, editing, testing, and publishing an Automation PowerShell runbook.

如果还没有 Azure 订阅,可以在开始前创建一个 Azure 帐户If you don't have an Azure subscription, create a Azure account before you begin.

登录 AzureSign in to Azure

通过 https://portal.azure.cn 登录到 Azure。Sign in to Azure at https://portal.azure.cn.

创建 RunbookCreate the runbook

首先,请创建 Runbook。First, create a runbook. 本快速入门中创建的示例 Runbook 默认输出 Hello WorldThe sample runbook created in this quickstart outputs Hello World by default.

  1. 打开自动化帐户。Open your Automation account.

  2. 单击“流程自动化”下的“Runbook”。 Click Runbooks under Process Automation. 此时会显示 Runbook 列表。The list of runbooks is displayed.

  3. 单击列表顶部的“创建 Runbook”。 Click Create a runbook at the top of the list.

  4. 在“名称”字段中输入 Hello-World 作为 Runbook 名称,并在“Runbook 类型”字段中选择“PowerShell”。 Enter Hello-World for the runbook name in the Name field, and select PowerShell for the Runbook type field.

    在页面中输入有关自动化 Runbook 的信息

  5. 单击创建Click Create. 此时会创建 Runbook 并打开“编辑 PowerShell Runbook”页。The runbook is created and the Edit PowerShell Runbook page opens.

    在 Runbook 编辑器中创作 PowerShell 脚本

  6. 将以下代码键入或者复制并粘贴到编辑窗格中。Type or copy and paste the following code into the edit pane. 此代码创建名为 Name、默认值为 World 的可选输入参数,并输出使用以下输入值的字符串:It creates an optional input parameter called Name with a default value of World, and outputs a string that uses this input value:

    param
    (
        [Parameter(Mandatory=$false)]
        [String] $Name = "World"
    )
    
    "Hello $Name!"
    
  7. 单击“保存”以保存 Runbook 的草稿副本。 Click Save to save a draft copy of the runbook.

    在 Runbook 编辑器中创作 PowerShell 脚本

测试 RunbookTest the runbook

创建 Runbook 之后,必须对其进行测试以验证其是否正常工作。Once the runbook is created, you must test the runbook to validate that it works.

  1. 单击“测试窗格”打开测试窗格 。Click Test pane to open the Test pane.

  2. 输入一个值作为“名称” ,然后单击“启动”。 Enter a value for Name, and click Start. 此时会启动测试作业并显示作业状态和输出。The test job starts and the job status and output display.

    Runbook 测试作业

  3. 单击右上角的“X”关闭“测试”窗格。 Close the Test pane by clicking the X in the upper right corner. 在显示的弹出窗口中选择“确定”。 Select OK in the popup that appears.

  4. 在“编辑 PowerShell Runbook”页中,单击“发布”将此 Runbook 作为正式版 Runbook 在帐户中发布。 In the Edit PowerShell Runbook page, click Publish to publish the runbook as the official version of the runbook in the account.

    Runbook 测试作业

运行 RunbookRun the runbook

Runbook 发布以后,会显示概览页。Once the runbook is published, the overview page is shown.

  1. 在 Runbook 概览页中,单击“启动”打开该 Runbook 的“启动 Runbook”配置页。 In the runbook overview page, click Start to open the Start Runbook configuration page for this runbook.

    Runbook 测试作业

  2. 将“名称”保留为空,以便使用默认值,然后单击“确定”。 Leave Name blank, so that the default value is used, and click OK. 此时会提交 Runbook 作业,并显示“作业”页。The runbook job is submitted, and the Job page appears.

    Runbook 测试作业

  3. 当作业状态为 RunningCompleted 时,单击“输出”打开“输出”窗格并查看 Runbook 输出。 When the job status is Running or Completed, click Output to open the Output pane and view the runbook output.

    Runbook 测试作业

清理资源Clean up resources

不再需要 Runbook 时,即可将其删除。When no longer needed, delete the runbook. 为此,请在 Runbook 列表中选择 Runbook,然后单击“删除”。 To do so, select the runbook in the runbook list, and click Delete.

后续步骤Next steps

本快速入门介绍了如何创建、编辑、测试和发布 Runbook,以及如何启动 Runbook 作业。In this quickstart, you've created, edited, tested, and published a runbook and started a runbook job. 若要详细了解自动化 Runbook,请继续阅读可以在自动化中创建和使用的不同 Runbook 类型的相关文章。To learn more about Automation runbooks, continue to the article on the different runbook types that you can create and use in Automation.