기술 자료

​
​

Development

User Acquisition

Monetization

산업 분야

Unity Cloud

Get Started

Asset Manager SDKs and services

Open Unity Dashboard

Unity Cloud

이 페이지는 선택한 언어로 제공되지 않습니다.
​
​
Unity Dashboard
  • Accounts
  • Organizations
  • Projects
  • Products
  • Billing
Developer Data
  • Introduction to the Developer Data Framework
  • Get started
  • View Diagnostics for your project
  • Privacy and consent
Unity Asset Manager
  • What's new
  • Asset Manager web
  • Asset Store
  • Manage Assets in the Editor
  • Unity Version Control
  • Developer documentation
Unity Pipeline Automation
  • About
  • Get started
  • Pipelines
    • Create a pipeline
    • Run a pipeline
    • Edit a pipeline
    • Delete a pipeline
    • Pipeline parameters
    • Steps
    • Custom Scripts
      • Use Custom Scripts
      • System parameters
      • Reference parameters
      • Coding patterns
  • Automations
  • Monitor jobs
  1. Unity Cloud Documentation
  2. Unity Pipeline Automation (beta)
  3. Custom Scripts (beta)

Coding patterns

Use coding best practices to ensure reliable and maintainable Custom Scripts.
읽는 시간 2분
최근 업데이트: 10달 전

You can use the below coding patterns to improve script reliability, prevent data overwrites, and make pipeline execution easier to debug and maintain.

Use unique file paths for each step’s output file

Custom Scripts enables you to write output data files to the job’s storage, so that subsequent steps in the pipeline can access them. For example, your script can generate a
.json
artifact that another step can parse. When you write output files to the job storage, use file paths unique to that step’s execution to prevent the files from being overwritten. This issue can occur if your script runs multiple times in a pipeline. Use the
{{system.stepId}}
parameter to avoid this.

Use error codes

Use logs and exit codes to ensure your scripts catch errors. This helps your pipeline users understand the issue. You can use the
exit
command to stop script execution and return an exit code. The exit code can be an integer in the range
0–255
, this helps you identify why the script execution stopped. An exit code of
0
indicates that the execution was successful.

Python Code example

This is as example of a Custom Script that demonstrates how to save pipeline execution data to a JSON file. This code example shows the following:
  • Pattern for logging
  • Referencing system parameters
  • Getting all pipeline parameters
  • Pattern for saving output data
  • Pattern for error handling
import jsonimport logging_LOG_PREFIX = "[My Custom Script]"logging.basicConfig( level=logging.INFO, format=f"{_LOG_PREFIX} - %(asctime)s - %(levelname)s - %(message)s", datefmt="%Y/%m/%d %H:%M:%S")logger = logging.getLogger(__name__)def _save_output(): """Saves output data to a JSON file.""" output_file = '/workspace/{{system.stepId}}/output.json' logger.info(f"Saving the following output data to {output_file}:") # If there are no parameters {{inputs.parameters}} evaluates to "null" # In Python you can handle this by converting "null" to None pipeline_params = {{inputs.parameters}} if """{{inputs.parameters}}""" != "null" else None output = { "step_id": "{{system.stepId}}", "job_id": "{{system.jobId}}", "random_uuid": "{{system.newUUID}}", "organization_id": "{{system.organizationId}}", "pipeline_params": pipeline_params, } logger.info(output) with open(output_file, 'w') as f: json.dump(output, f, ensure_ascii=False, indent=4)if __name__ == "__main__": logger.info("My custom script initialized.") try: _save_output() except Exception as e: logger.error(f"Action failed: {e}") exit(1)

Copyright © 2026 Unity Technologies
법률 정보개인정보 처리방침쿠키Documentation Terms of Use개인 정보 판매 또는 공유 금지개인정보 보호 선택(쿠키 설정)

'Unity', Unity 로고 및 기타 Unity 상표는 미국 및 기타 지역 내 Unity Technologies 또는 그 계열사의 상표 또는 등록상표입니다(자세한 내용은 여기에서 확인하세요). 기타 명칭 또는 브랜드는 해당 소유자의 상표입니다.

일부 페이지는 편의를 위해 기계 번역되었으며 부정확한 내용이 있을 수 있습니다. 정보가 상충되는 경우, 영어 버전을 우선으로 참조하세요.

  • 보고 있는 페이지
    • Use unique file paths for each step’s output file

    • Use error codes

    • Python Code example


이 페이지의 문제 보고