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.
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)?
ScriptApp.newTrigger()
, which version of script is used.I understand your question like above. If my understanding is correct, how about this answer? Please think of this as one of several answers.
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.
function myFunction() {lib.myFunction()}
is put. This script runs the function of the library.
ScriptApp.newTrigger("myFunction")
in the project to use the library. At this time, when the trigger is run, the selected version of library is used. By this, the latest script of library is not used. Users can use the stable script of the version you selected.If I misunderstand your question, I'm sorry.
Yes, it always point to the "head" as versioned deployments are only available for Gmail Add-ons.
The above is based on that the only the guide to publish a Gmail add-on includes as step the creation of a versioned deployment -> https://developers.google.com/gmail/add-ons/how-tos/publish#step_1_create_a_versioned_deployment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With