

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 作业捆绑包的作业模板元素
<a name="build-job-bundle-template"></a>

作业模板定义了运行时环境和作为 Deadline Cloud 作业的一部分运行的进程。你可以在模板中创建参数，这样它就可以用来创建只在输入值上有所不同的作业，就像编程语言中的函数一样。

当您向 Deadline Cloud 提交作业时，该任务将在应用于该队列的任何队列环境中运行。队列环境是使用 Open Job Description (OpenJD) 外部环境规范构建的。有关详细信息，请参阅 OpenJD GitHub 存储库中的[环境模板](https://github.com/OpenJobDescription/openjd-specifications/wiki/2023-09-Template-Schemas#12-environment-template)。

有关使用 OpenJD 作业模板创建作业的[简介，请参阅在 OpenJD GitHub 存储库中创建作业](https://github.com/OpenJobDescription/openjd-specifications/wiki/Introduction-to-Creating-a-Job)简介。更多信息可以在[作业的运行方式](https://github.com/OpenJobDescription/openjd-specifications/wiki/How-Jobs-Are-Run)中找到。OpenJD GitHub 存储库的`samples`目录中有作业模板示例。

您可以用 YAML 格式 (`template.yaml`) 或 JSON 格式 (`template.json`) 定义作业模板。本节中的示例以 YAML 格式显示。

例如，该`blender_render`示例的作业模板将输入参数定义`BlenderSceneFile`为文件路径：

```
- name: BlenderSceneFile
  type: PATH
  objectType: FILE
  dataFlow: IN
  userInterface:
    control: CHOOSE_INPUT_FILE
    label: Blender Scene File
    groupLabel: Render Parameters
    fileFilters:
    - label: Blender Scene Files
      patterns: ["*.blend"]
    - label: All Files
      patterns: ["*"]
  description: >
    Choose the Blender scene file to render. Use the 'Job Attachments' tab
    to add textures and other files that the job needs.
```

该`userInterface`属性定义了使用命令的命令行自动生成的用户界面的行为，也定义了在 Autodesk Maya 等应用程序的作业提交插件中自动生成的用户界面的行为。`deadline bundle gui-submit`

在此示例中，用于输入`BlenderSceneFile`参数值的 UI 控件是一个仅显示文件的文件选择对话框。`.blend`

![用于输入 OpenJD 作业模板的场景文件参数的用户界面控件。](http://docs.aws.amazon.com/zh_cn/deadline-cloud/latest/developerguide/images/blender_submit_scene_file_widget.png)


有关使用该`userInteface`元素的更多示例，请参阅存储库中的 [gui\_control\_showcase](https://github.com/aws-deadline/deadline-cloud-samples/tree/mainline/job_bundles/gui_control_showcase) 示例。[deadline-cloud-samples](https://github.com/aws-deadline/deadline-cloud-samples/tree/mainline) GitHub

`objectType`和`dataFlow`属性控制从作业捆绑包提交作业时作业附件的行为。在本例中`objectType: FILE`，and `dataFlow:IN` 表示的值`BlenderSceneFile`是作业附件的输入文件。

相比之下，`OutputDir`参数的定义有`objectType: DIRECTORY`和`dataFlow: OUT`：

```
- name: OutputDir
  type: PATH
  objectType: DIRECTORY
  dataFlow: OUT
  userInterface:
    control: CHOOSE_DIRECTORY
    label: Output Directory
    groupLabel: Render Parameters
  default: "./output"
  description: Choose the render output directory.
```

作业附件使用该`OutputDir`参数的值作为作业写入输出文件的目录。

有关`objectType`和`dataFlow`属性的更多信息，请参阅 Ope [n Job Description 规范[JobPathParameterDefinition](https://github.com/OpenJobDescription/openjd-specifications/wiki/2023-09-Template-Schemas#22-jobpathparameterdefinition)](https://github.com/OpenJobDescription/openjd-specifications)中的

`blender_render`作业模板示例的其余部分将作业的工作流程定义为单个步骤，动画中的每一帧都呈现为单独的任务：

```
steps:
- name: RenderBlender
  parameterSpace:
    taskParameterDefinitions:
    - name: Frame
      type: INT
      range: "{{Param.Frames}}"
  script:
    actions:
      onRun:
        command: bash
        # Note: {{Task.File.Run}} is a variable that expands to the filename on the worker host's
        # disk where the contents of the 'Run' embedded file, below, is written.
        args: ['{{Task.File.Run}}']
    embeddedFiles:
      - name: Run
        type: TEXT
        data: |
          # Configure the task to fail if any individual command fails.
          set -xeuo pipefail

          mkdir -p '{{Param.OutputDir}}'

          blender --background '{{Param.BlenderSceneFile}}' \
                  --render-output '{{Param.OutputDir}}/{{Param.OutputPattern}}' \
                  --render-format {{Param.Format}} \
                  --use-extension 1 \
                  --render-frame {{Task.Param.Frame}}
```

例如，如果`Frames`参数的值为`1-10`，则它定义 10 个任务。每个 has task 的`Frame`参数值都不同。要运行任务，请执行以下操作：

1. 例如，嵌入式文件`data`属性中的所有变量引用都会被展开`--render-frame 1`。

1. 该`data`属性的内容将写入磁盘上会话工作目录中的一个文件中。

1. 任务的`onRun`命令解析为，`bash {{location of embedded file}}`然后运行。

有关嵌入文件、会话和路径映射位置的更多信息，请参阅 Open [Job Description 规范中的作业运行方式](https://github.com/OpenJobDescription/openjd-specifications/wiki/How-Jobs-Are-Run)[。](https://github.com/OpenJobDescription/openjd-specifications/wiki/How-Jobs-Are-Run)

[deadline-cloud-samples/job\_bundles](https://github.com/aws-deadline/deadline-cloud-samples/tree/mainline/job_bundles) 存储库中还有更多作业模板示例，以及随开放职位[描述规范提供的模板示例](https://github.com/OpenJobDescription/openjd-specifications/tree/mainline/samples)。