我在Azure有一本使用自动化的运行手册。它是从一个表中得到一个整数结果,它可以返回正确的值。下面是我正在使用的代码,它可以工作。
$SQLServerCred = Get-AutomationPSCredential -Name "SqlCredential"
#Import the SQL Server Name from the Automation variable.
$SQL_Server_Name = Get-AutomationVariable -Name "SqlServer"
#Import the SQL DB from the Automation variable.
$SQL_DB_Name = Get-AutomationVariable -Name "Database"
$Query = "select max(je.ExecutionOrder) as LastStepExecuted
from PPoint.JobExecutionHistory je
where je.EventType = 'Start'
and je.JobRunId = PPoint.fnGetJobRunID()"
invoke-sqlcmd -ServerInstance "$SQL_Server_Name" -Database "$SQL_DB_Name" -Credential $SQLServerCred -Query "$Query" -Encrypt我的下一步是将查询的结果分配给一个变量,然后计算它,看看它是否应该调用另一个runbook。因此,我希望有一个名为LastStep的变量,并从下面的查询中为它分配LastStepExecuted的整数结果。然后我想沿着这条线做一些事情(这是伪代码)。
if LastStep = 2147483647
call another runbook
else
do nothing - end the runbook我尝试过几种方法来捕获变量中的LastStepExecuted,但我无法理解它。有人能帮忙吗?
任何帮助或建议都很感激。
发布于 2022-02-04 07:00:12
您可以使用Start-AzAutomationRunbook cmdlet从自动化帐户内的另一个运行簿触发子运行簿。
$SQLServerCred = Get-AutomationPSCredential -Name "SqlCredential"
#Import the SQL Server Name from the Automation variable.
$SQL_Server_Name = Get-AutomationVariable -Name "SqlServer"
#Import the SQL DB from the Automation variable.
$SQL_DB_Name = Get-AutomationVariable -Name "Database"
$Query = "select max(je.ExecutionOrder) as LastStepExecuted
from PPoint.JobExecutionHistory je
where je.EventType = 'Start'
and je.JobRunId = PPoint.fnGetJobRunID()"
$LastStep=invoke-sqlcmd -ServerInstance "$SQL_Server_Name" -Database "$SQL_DB_Name" -Credential $SQLServerCred -Query "$Query" -Encrypt
if($LastStep -eq 2147483647)
{
Start-AzAutomationRunbook -AutomationAccountName "MyAutomationAccount" -Name "Test-ChildRunbook" -ResourceGroupName "LabRG" -DefaultProfile $AzureContext -Parameters $params -Wait
}
else
{
Write-Output "conditionfailed the value of $LastStep"
}您可以参考这文档,有关蔚蓝自动化中的模块化运行簿。
https://stackoverflow.com/questions/70941890
复制相似问题