Deploy new version of Apps Script using Google Apps Script java API

427 Views Asked by At

I am using the Google App Script java API to deploy the code. I am performing the following steps:

1. Update the latest code

Content content = new Content();
content.setFiles(files);
Content updatedContent = scriptService.projects().updateContent(scriptId, content).execute();

2. Create a new version

Version version = new Version();
version.setDescription("test create version");
Version createdVersion = scriptService.projects().versions().create(scriptId, version).execute();

3. Deploy the latest version

DeploymentConfig deploymentConfig = new DeploymentConfig();
deploymentConfig.setDescription("test deployment");
deploymentConfig.setVersionNumber(createdVersion.getVersionNumber());
deploymentConfig.setManifestFileName("appsscript");

Deployment deploymentCreated = scriptService.projects().deployments().create(scriptId, deploymentConfig).execute();

When I log into script.google.com I am able to view the latest version that I created. It shows the status as deployed. In the script editor, I am able to view the latest code as well. Now, when I invoke the apps script the requests are still handled by the older version. Could somebody let me know if there is something wrong with the way I am using the API?

1

There are 1 best solutions below

0
On
  1. try to set deployment version (greater then old one).

    Version version = new Version();
    version.setDescription("test create version");
    version.setVersionNumber(3);
    Version createdVersion = scriptService.projects().versions().create(scriptId, version).execute();
    
  2. delete the deployment when it's no longed needed

    service.projects().deployments()
        .delete(scriptId, deploymentCreated.getDeploymentId()).execute();