简体   繁体   English

如何从命令行将 Runbook 导入 azure 资源组

[英]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.

相关问题 如何从Azure Resource Manager Runbook登录? - How to login from an Azure Resource Manager Runbook? 您如何 DeployIfNotExists 具有 azure 策略的资源组? - How do you DeployIfNotExists a resource group with azure policy? Azure Runbook-从单独的Runbook导入命令 - Azure Runbooks - Import Commands From Separate Runbook 如何从命令行使用 .NET 5.0 配置 Azure VM? - How do you configuring Azure VMs with .NET 5.0 from the command line? Azure 自动化运行手册 - 随机发生的错误:找不到资源组“{resource-group-name}” - Azure Automation Runbook - Randomly occurring error: Resource group '{resource-group-name}' could not be found 如何在 Azure Python 3 Runbook 中获得 SQL 令牌身份验证? - How do you get SQL Token authentication working within an Azure Python 3 Runbook? 我是否必须在Powershell Runbook(azure)中导入模块? - Do I have to import modules in powershell runbook (azure)? 您如何 select 仅从 Azure 命令 'az group list in powershell' 的“结果”数组中的一个属性? - how do you select just one property from an array of “results” from the Azure command 'az group list in powershell'? 来自另一个 RunBook 的 Azure 自动化 RunBook - Azure Automation RunBook from Another RunBook 如何将 Azure Cosmos DB 疼痛程序从一个资源组导入到另一个 - How to import export Azure Cosmos DB sore procedure from One resource group to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM