0

我正在尝试使用将output_files 作为任务参数的任务创建 Azure 批处理作业

tasks = list()
command_task = (r"cmd /c dir")

# Not providing actual property value for security purpose
containerName = r'ContainerName'
azureStorageAccountName = r'AccountName'
azureStorageAccountKey = r'AccountKey'

sas_Token = generate_account_sas(account_name=azureStorageAccountName, account_key=azureStorageAccountKey, resource_types=ResourceTypes(object=True), permission=AccountSasPermissions(read=True, write=True), expiry=datetime.datetime.utcnow() + timedelta(hours=1))

url = f"https://{azureStorageAccountName}.blob.core.windows.net/{containerName}?{sas_Token}"

output_file = batchmodels.OutputFile(
        file_pattern=r"..\std*.txt",
        destination=batchmodels.OutputFileDestination(
            container=batchmodels.OutputFileBlobContainerDestination(container_url=url),
            path="abc"),
        upload_options='taskCompletion')

tasks.append(batchmodels.TaskAddParameter(id='Task1', display_name='Task1', command_line=command_task, user_identity=user, output_files=[output_file]))

batch_service_client.task.add_collection(job_id, tasks)

在调试此代码时,我收到异常, 但在删除output_files参数时,一切正常,并且作业是使用任务创建的。在此处输入图像描述

4

1 回答 1

0

我在创建 OutputFile 对象时错过了 upload_options 对象:

output_file = batchmodels.OutputFile(
        file_pattern=r"..\std*.txt",
        destination=batchmodels.OutputFileDestination(
            container=batchmodels.OutputFileBlobContainerDestination(container_url=url),
            path="abc"),
        upload_options=batchmodels.OutputFileUploadOptions('taskCompletion'))
于 2021-06-17T13:35:44.450 回答