Azure自定义扩展失败,并显示错误消息:“完成的执行命令"; [英] Azure custom extension fails with Error message:"Finished executing command"
问题描述
我开始在Azure中测试自定义扩展,并以非常简单的json和ps1脚本开始.我的json文件看起来像这样:
I am starting to test custom extensions in Azure and started with very simple json and ps1 script. My json file looks like this:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'),'/RunDateTimeScript')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://github.com/username/repo/blob/master/writedatetime.ps1"
],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File writedatetime.ps1"
}
}
}
]
}
我的powershell脚本是一个单行代码:
And my powershell script is a oneliner:
(Get-Date).DateTime | Out-File "C:\Testing.txt" -Append
但是,当我运行常规的powershell部署命令时:
However, when I run the usual powershell deployment command:
New-AzureRmResourceGroupDeployment -ResourceGroupName MyResources -TemplateFile .\extensionexample.json -vmName MyVmName01
结果我失败了:
消息":"VM在处理扩展时报告了故障'RunDateTimeScript'.错误消息:\执行命令完成\"."
"message": "VM has reported a failure when processing extension 'RunDateTimeScript'. Error message: \"Finished executing command\"."
那我做错了什么以及如何解决呢?
So what I am doing wrong and how to fix this?
推荐答案
与此相关的问题非常愚蠢.我为github使用了错误的网址,因为它应该是原始网址,而不是模板中的网址.即 https://raw.githubusercontent.com/username/repo/master/script.ps1
The problem with this was pretty dumb. I used the wrong url for github as it should be the raw instead of the one in template. i.e https://raw.githubusercontent.com/username/repo/master/script.ps1
这篇关于Azure自定义扩展失败,并显示错误消息:“完成的执行命令";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!