0

我在 Azure 数据工厂中有一个自定义活动,它尝试执行以下命令:

PowerShell.exe -Command "Write-Host 'Hello, world!'"

但是,当我从 Azure 数据工厂中调试(运行)此命令时,它运行了很长时间,最后失败了。

我猜它失败了,因为它可能找不到“PowerShell.exe”。如何确保 ADF 自定义活动可以访问 PowerShell.exe?

一些网站说要指定一个包(.zip 文件),其中包含执行 exe 所需的所有内容。但是,由于 PowerShell 来自 Microsoft,我认为压缩 PowerShell 目录并将其指定为自定义活动的包是不合适的。

请建议我如何从 Azure 数据工厂的自定义活动中执行 PowerShell 命令。谢谢!

每当我搜索“从 Azure 数据工厂中的自定义活动执行 PowerShell”时,搜索结果都会更多地讨论用于触发启动 ADF 管道的 Az PowerShell 命令。

我在 Stackoverflow.com 中看到了两个线程,其中答案只是指定使用自定义活动,而答案并不特定于来自 ADF 的 PowerShell 命令调用

这是该任务的 JSON:

{ "name": "ExecutePs1CustomActivity", "properties": { "activities": [ { "name": "ExecutePSScriptCustomActivity", "type": "Custom", "dependsOn": [], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "command": "PowerShell.exe -Command \"Write-Host 'Hello, world!'\"", "referenceObjects": { "linkedServices": [], "datasets": [] } }, "linkedServiceName": { "referenceName": "Ps1CustomActivityAzureBatch", "type": "LinkedServiceReference" } } ], "annotations": [] } }

我看到“进行中”3 分钟(180 秒),然后显示为“失败”。

4

1 回答 1

0

我建议您将所有脚本任务移动到 powershell 文件中,并将其复制到与您的自定义活动链接的存储帐户。. 完成后尝试如下调用它:

powershell .\script.ps1

您还可以在 json 中提供脚本的路径,如下所示:

{
  "name": "MyCustomActivityPipeline",
  "properties": {
    "description": "Custom activity sample",
    "activities": [{
      "type": "Custom",
      "name": "MyCustomActivity",
      "linkedServiceName": {
        "referenceName": "AzureBatchLinkedService",
        "type": "LinkedServiceReference"
      },
      "typeProperties": {
        "command": "helloworld.exe",
        "folderPath": "customactv2/helloworld",
        "resourceLinkedService": {
          "referenceName": "StorageLinkedService",
          "type": "LinkedServiceReference"
        }
      }
    }]
  }
}

请尝试一下,看看它是否有帮助。另外,我建议您对管道步骤进行故障排除以查找详细错误。

还有你的第二点“一些网站说要指定一个包(.zip 文件),其中包含执行 exe 所需的所有内容。” 当您使用 dot net 构建自定义活动时,这是必需的,然后必须复制所有 Dll 和 Exe 才能执行。

希望能帮助到你。

于 2019-09-10T08:16:30.053 回答