def METHOD_NAME(cmd,  # pylint: disable=too-many-locals
              client,
              registry_name,
              source_location,
              image_names=None,
              resource_group_name=None,
              agent_pool_name=None,
              timeout=None,
              arg=None,
              secret_arg=None,
              docker_file_path='',
              no_format=False,
              no_push=False,
              no_logs=False,
              no_wait=False,
              platform=None,
              target=None,
              auth_mode=None,
              log_template=None):
    _, resource_group_name = validate_managed_registry(
        cmd, registry_name, resource_group_name, BUILD_NOT_SUPPORTED)
    from ._client_factory import cf_acr_registries_tasks
    client_registries = cf_acr_registries_tasks(cmd.cli_ctx)
    if os.path.exists(source_location):
        if not os.path.isdir(source_location):
            raise CLIError("Source location should be a local directory path or remote URL.")
        # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location.
        # Otherwise, it's based on current working directory.
        if not docker_file_path:
            docker_file_path = os.path.join(source_location, "Dockerfile")
            logger.info("'--file or -f' is not provided. '%s' is used.", docker_file_path)
        _check_local_docker_file(docker_file_path)
        tar_file_path = os.path.join(tempfile.gettempdir(
        ), 'build_archive_{}.tar.gz'.format(uuid.uuid4().hex))
        try:
            # NOTE: os.path.basename is unable to parse "\" in the file path
            original_docker_file_name = os.path.basename(
                docker_file_path.replace("\\", "/"))
            docker_file_in_tar = '{}_{}'.format(
                uuid.uuid4().hex, original_docker_file_name)
            source_location = upload_source_code(
                cmd, client_registries, registry_name, resource_group_name,
                source_location, tar_file_path,
                docker_file_path, docker_file_in_tar)
            # For local source, the docker file is added separately into tar as the new file name (docker_file_in_tar)
            # So we need to update the docker_file_path
            docker_file_path = docker_file_in_tar
        except Exception as err:
            raise CLIError(err)
        finally:
            try:
                logger.debug("Deleting the archived source code from '%s'...", tar_file_path)
                os.remove(tar_file_path)
            except OSError:
                pass
    else:
        # NOTE: If docker_file_path is not specified, the default is Dockerfile. It's the same as docker build command.
        if not docker_file_path:
            docker_file_path = "Dockerfile"
            logger.info("'--file or -f' is not provided. '%s' is used.", docker_file_path)
        source_location = check_remote_source_code(source_location)
        logger.warning("Sending context to registry: %s...", registry_name)
    is_push_enabled = _get_push_enabled_status(no_push, image_names)
    platform_os, platform_arch, platform_variant = get_validate_platform(cmd, platform)
    DockerBuildRequest, PlatformProperties = cmd.get_models(
        'DockerBuildRequest',
        'PlatformProperties',
        operation_group='runs')
    docker_build_request = DockerBuildRequest(
        agent_pool_name=agent_pool_name,
        image_names=image_names,
        is_push_enabled=is_push_enabled,
        source_location=source_location,
        platform=PlatformProperties(
            os=platform_os,
            architecture=platform_arch,
            variant=platform_variant
        ),
        docker_file_path=docker_file_path,
        timeout=timeout,
        arguments=(arg if arg else []) + (secret_arg if secret_arg else []),
        target=target,
        credentials=get_custom_registry_credentials(
            cmd=cmd,
            auth_mode=auth_mode
        ),
        log_template=log_template
    )
    queued = LongRunningOperation(cmd.cli_ctx)(client_registries.begin_schedule_run(
        resource_group_name=resource_group_name,
        registry_name=registry_name,
        run_request=docker_build_request))
    run_id = queued.run_id
    logger.warning("Queued a build with ID: %s", run_id)
    if no_wait:
        return queued
    logger.warning("Waiting for an agent...")
    if no_logs:
        from ._run_polling import get_run_with_polling
        return get_run_with_polling(cmd, client, run_id, registry_name, resource_group_name)
    return stream_logs(cmd, client, run_id, registry_name, resource_group_name, timeout, no_format, True)