本文介绍了以编程方式创建触发器时如何使用版本化的部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以编程方式(即通过 ScriptApp.newTrigger())创建触发器时,它是否始终指向头部"部署或最新发布(版本化)的部署?(请参见此处.)

When creating a trigger programmatically, i.e. through ScriptApp.newTrigger(), does it always point to the "head" deployment, or the most recent published (versioned) deployment? (See documentation on deployment types here.)

对于上下文,我正在多用户环境中分发脚本,该环境依赖触发器每隔几分钟运行一次.我试图确保脚本的所有客户端都不会立即拾取开发中所做的更改(即,在发布这些更改之前),因为这实际上意味着开发人员中的所有代码更新都将立即对所有用户生效.

For context, I'm distributing a script in a multi-user environment which relies on triggers to run every few minutes. I'm trying to ensure that changes made in development (i.e. before publishing those changes) are not picked up immediately by all the clients of the script, as this effectively means any code updates in dev are instantly live for all users.

如果触发器只能指向头部部署,那么将触发器指向可以在dev(头部版本)中安全更新的代码的最佳实践是什么?

If triggers can only point to head deployments, what are best practices for pointing them at code which can be safely updated in dev (head version)?

推荐答案

  1. 您想知道,当 ScriptApp.newTrigger()安装触发器时,将使用哪个版本的脚本.
  2. 您想通过选择脚本版本来了解安装触发器的方法.
  1. You want to know that when a trigger is installed by ScriptApp.newTrigger(), which version of script is used.
  2. You want to know the method for installing a trigger by selecting version of script.

我理解您的上述问题.如果我的理解是正确的,那么这个答案呢?请认为这是几个答案之一.

I understand your question like above. If my understanding is correct, how about this answer? Please think of this as one of several answers.

  • 通过 ScriptApp.newTrigger()安装触发器时,尽管当前项目的触发器"中未显示"Deployment"的值,但最新的脚本由已安装的脚本运行扳机.这种情况与脚本的版本无关.使用当前最新的脚本.

  • When a trigger is installed by ScriptApp.newTrigger(), although the value of "Deployment" is not shown in "Current project's triggers", the latest script is run by the installed trigger. This situation is independent of the version of script. The current latest script is used.

如果手动安装了触发器,则可以在选择应运行的部署"中选择部署版本.

If the trigger is manually installed, you can select the deployment version at "Choose which deployment should run".

  • 不幸的是,在当前阶段,脚本尚无法实现.我认为这可能会在将来的更新中实现.

为了通过选择脚本版本安装触发器,作为一种解决方法,我建议使用一个库.此解决方法的流程如下.这是示例流程.

In order to install a trigger by selecting version of script, as a workaround, I would like to propose to use a library. The flow of this workaround is as follows. This is a sample flow.

  1. 创建2个独立项目.
    • 一个用作库.
    • 另一个用作使用该库的项目.
  • 将库安装到该项目.
  • 您可以通过选择库的版本来选择要使用户运行的脚本.
  • 触发器已安装到该项目.

笔记:

  • 您还可以在清单文件(appsscript.json)中查看库的版本.可以通过脚本修改此文件.这样,您还可以通过脚本触发器使用脚本来修改脚本的版本.
  • 如果我误解了你的问题,对不起.

    If I misunderstand your question, I'm sorry.

    这篇关于以编程方式创建触发器时如何使用版本化的部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 14:38