[英]How do you import runbook to azure resource group from the command line
I have a DevOps pipeline for setting up various resources within a resource group in Azure.我有一个 DevOps 管道,用于在 Azure 的资源组中设置各种资源。
As part of the pipeline I would like to import a runbook to the resource group, and set up a schedule for it to run within the portal (not set up a DevOps schedule).作为管道的一部分,我想将 Runbook 导入资源组,并为其在门户中运行设置一个计划(而不是设置 DevOps 计划)。
The docs explain how to create a runbook from the azure cli:文档解释了如何从 azure cli 创建 Runbook:
az automation runbook create --automation-account-name "myAutomationAccount" --resource-group "rg" --name "myRunbook" --type "PowerShell" --location "East US 2"
but do not explain how import the runbook from a DevOps repo.但不解释如何从 DevOps 存储库导入 Runbook。
How do I import the runbook from a DevOps pipeline using the cli.如何使用 cli 从 DevOps 管道导入 Runbook。
Also how can I create a schedule in the portal (using the cli within the DevOps pipeline) on which to run the runbook?另外,如何在门户中创建计划(使用 DevOps 管道中的 cli)来运行 Runbook?
I import runbooks regularly.我会定期导入 Runbook。 But I go a little different way.但我走的路有点不同。 In Azure DevOps, I call a webhook with parameters and then start a runbook that imports the runbooks from Azure DevOps.在 Azure DevOps 中,我使用参数调用 webhook,然后启动一个从 Azure DevOps 导入 Runbook 的 Runbook。 In addition, I no longer use the PowerShell modules for the import but do everything via the API, which is much faster.此外,我不再使用 PowerShell 模块进行导入,而是通过 API 执行所有操作,这要快得多。
https://docs.microsoft.com/en-us/rest/api/automation/runbook/create-or-update https://docs.microsoft.com/en-us/rest/api/automation/runbook/create-or-update
First, I create the runbook as a draft, adding the content and publishing the runbook.首先,我将 Runbook 创建为草稿,添加内容并发布 Runbook。
It can also be done the other way, directly from Azure DevOps, but Azure Automation is my main tool, so I did it there.也可以通过其他方式直接从 Azure DevOps 完成,但 Azure 自动化是我的主要工具,所以我在那里完成了。 Of course, there is still source control in Azure Automation, where you can also have the code imported automatically.当然,Azure 自动化中仍然有源代码控制,您也可以在其中自动导入代码。 But I can do everything the same way with the runbook, and I'm very flexible with the webhook!但是我可以使用 Runbook 以相同的方式完成所有操作,而且我对 webhook 非常灵活!
Stefan斯特凡
Figured out how to do it using the following commands with the appropriate arguments passed through --automation-account-name --name --resource-group --type Powershell --location
for the first call etc:弄清楚如何使用以下命令和通过--automation-account-name --name --resource-group --type Powershell --location
传递的适当参数进行第一次调用等:
az automation runbook create
az automation runbook replace-content --content @./Repo_name/runbook_name.ps1
az automation runbook publish
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.