Nir
Nir

Reputation: 1678

App script web change version for each deploy

I created a web app for my google sheet script. I deployed it with version 1 and and it works

Now I want to make on going changes and deploy my changes, Do I need to increase the version for each change I deploy? or can I update on current version?

Also, is there a way to get the current version programmaticaly?

Upvotes: 5

Views: 3842

Answers (4)

Connor
Connor

Reputation: 4844

It's much easier than everyone makes it sound

  1. Go to Deploy:

enter image description here

  1. Click "Manage deployments"

  2. Under Configuration click the edit pencil

enter image description here

  1. Under "Version" click "New Version"

enter image description here

  1. Click "Deploy" it will auto increment the version for you

Upvotes: 5

Tanaike
Tanaike

Reputation: 201378

For your situation, I would like to introduce because I had a workaround that I also use.

For question 1 :

In generally, when the script of Web Apps was updated, the project version is required to be increased and Web Apps is redeployed with the new version.

But if you want to deploy Web Apps without increasing the version, as a workaround, you can achieve it by using a library. The flow of for this workaround is as follows.

  1. Create 2 projects.
    • One is the project that Web Apps is deployed.
      • It supposes that this is the project that you are using now.
    • Another project is used as a library. Please create this as a standalone project.
      • Please create a version.
        • On script editor
          • File -> Manage versions...
          • After input description, please click "Save new version".
      • Please copy this script ID. This is used for installing the library.
  2. For the project that Web Apps is deployed.
    • Please install the library project as a library.
      • On script editor
        • Resources -> Libraries...
        • For "Add a library", please input the file ID of library project.
        • Turn on "Development mode".
        • Set the version to the saved version.
        • In this sample, please set "Identifier" to "lib".
    • Please copy and paste the following function. In this project, the script is only this. And please save the project after copy and paste it.
      • function doGet(e) {return lib.main(e)}
    • Please deploy Web Apps as a new version.
    • After this setting, you are not required to modify this project.
  3. For the project which is used as a library.
    • Please copy and paste the following function.
      • function main(e) {return yourfunction(e)}
      • yourfunction(e) is the function in the project that you are using.

In this workaround, when you want to modify the script, please modify the library project. By this, when the library is updated, the project which deployed Web Apps is automatically updated because "Development mode" is turned on when the library is installed. This update is also reflected to Web Apps. So the script of Web Apps can be updated without increasing the version.

As a sample, the scripts for both project after making the settings described above are as follows:

For the project that Web Apps is deployed.

function doGet(e) {
  return lib.main(e);
}

For the project which is used as a library.

function main(e) {
  return yourfunction(e);
}

function yourfunction(e) {

   do something: The script which is run when users accessed to Web Apps.

  return something
}

For question 2 :

In order to retrieve the current version of the project, you can use Apps Script API. This is also answered by tehhowch. In a recent update, users got to be able to retrieve and create the project versions. By using this, you can achieve this. The required scope is https://www.googleapis.com/auth/script.projects or https://www.googleapis.com/auth/script.projects.readonly.

The endpoint for retrieving the version list is as follows.
GET https://script.googleapis.com/v1/projects/### scriptId ###/versions
If you want to create the new version using script, you can use the following endpont.
POST https://script.googleapis.com/v1/projects/### scriptId ###/versions

Request body is

{
 "versionNumber": 3,
 "description": "sample description"
}

References :

If this was not useful for you, I'm sorry.

Upvotes: 6

tehhowch
tehhowch

Reputation: 9872

When creating a web app for apps script, two links are given:

  1. The one ending exec will only load the specified published version of the code.
  2. The one ending dev will load the latest saved code (allowing for testing of code prior to making a new version).

Programmatic control of the deployed version is available via the Apps Script API, and to a Dev environment via clasp.

Upvotes: 1

Andrew Roberts
Andrew Roberts

Reputation: 2798

You need to increase the version for each change, unless you use the "dev" version of the app when it will always display the latest version. This will only be visible when you are logged into your account though.

Upvotes: 0

Related Questions