Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script - Deploy as Webapp - new version every time?

Changes I make to my Code.gs file don't seem to be recognized unless I deploy as webapp under a new version. Is this the designed behavior or am I doing something wrong elsewhere?

like image 289
Daveh0 Avatar asked Sep 13 '19 00:09

Daveh0


2 Answers

In case you're trying to update a deployment and want to keep the same URL, here's how to do it as of March 2021 :

  • Deploy -> New deployment will create a new URL every single time. I believe the purpose is to have multiple versions of the program that can be tested without disrupting the main version.

You want this instead :

  • Deploy -> Manage deployments : under "Active" at top left, make sure you have the right deployment selected (hover over URL to see it all)
  • Then click on the pencil icon at the top right to edit this deployment. Click on the "Version" dropbox and "New version". Then "Deploy". This will update THIS version with your newest code and keep the same URL as you are not making a new deployment (just updating) ! Unfortunately, this wasn't made very clear anywhere that I could find.

If you have a dozen other actives that you don't want, you can archive them (icon is right next to the pencil). If you archived the URL you were actually using in the past, you can bring it back by clicking on it under "Archived", then pencil icon, then Deploy.

  • Under Deploy -> Test deployment, you have your /dev version which is your latest code live (like the old editor)
like image 167
Raphael Avatar answered Nov 11 '22 00:11

Raphael


How about this answer? Please think of this as just one of several answers.

At the project that Web Apps is deployed, when the script in the project was modified, the Web Apps is required to be redeployed as new version. By this, the latest script is reflected to the Web Apps. This is the normal specification. I think that this situation might be supposed to separate the developing script and stable script.

Automatically reflecting latest script to Web Apps

There are several methods that the latest script can be automatically reflected to Web Apps when the script was modified.

1. Use developer mode

When the developer mode is used, the latest script can be used for the Web Apps without redeploying as new version. When you deploy the Web Apps, you can see "latest code" which has a link. The URL is like https://script.google.com/macros/s/###/dev. By using this URL, when the script was modified, you can use the latest script at Web Apps.

As an important point, when you use this, please use the access token. By this, you can access to the Web Apps. The sample curl can be seen at here.

2. Use library

If you want to automatically use the latest script using the URL like https://script.google.com/macros/s/#####/exec, it can be achieved using a library. The preparation is as follows.

  1. Create 2 projects which are project "A" and project "B".
    • Project "A" is used as the project deployed Web Apps. Project "B" is used as a GAS library.
  2. At Project "A", install Project "B" as the GAS library. At that time, set "Development mode" as "Turn ON".
  3. At Project "A", put the function function doGet(e) {return library.run(e)}.
    • In this case, the library name supposes library.
  4. At Project "B", put the function function run(e) { do something }.
    • When you want to modify the script of Web Apps, please modify the script of Project "B".

By above settings, when the script of Project "B" is modified, the latest script is automatically reflected to the Web Apps. By this, it is not required to redeploy as new version.

References:

  • Web Apps
  • Libraries
  • Taking advantage of Web Apps with Google Apps Script

If I misunderstood your question and this was not the direction you want, I apologize.

like image 28
Tanaike Avatar answered Nov 11 '22 00:11

Tanaike