Skip to content
Ona Docs

UpsertAutomationsFile

client.environments.automations.upsert(AutomationUpsertParams { automationsFile, environmentId } body, RequestOptionsoptions?): AutomationUpsertResponse { updatedServiceIds, updatedTaskIds }
POST/gitpod.v1.EnvironmentAutomationService/UpsertAutomationsFile

Upserts the automations file for the given environment.

Use this method to:

  • Configure environment automations
  • Update automation settings
  • Manage automation files

Examples

  • Update automations file:

    Updates or creates the automations configuration.

    environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048"
    automationsFile:
      services:
        web-server:
          name: "Web Server"
          description: "Development web server"
          commands:
            start: "npm run dev"
            ready: "curl -s http://localhost:3000"
          triggeredBy:
            - postDevcontainerStart
      tasks:
        build:
          name: "Build Project"
          description: "Builds the project artifacts"
          command: "npm run build"
          triggeredBy:
            - postEnvironmentStart
ParametersExpand Collapse
body: AutomationUpsertParams { automationsFile, environmentId }
automationsFile?: AutomationsFile { services, tasks }

WARN: Do not remove any field here, as it will break reading automation yaml files. We error if there are any unknown fields in the yaml (to ensure the yaml is correct), but would break if we removed any fields. This includes marking a field as “reserved” in the proto file, this will also break reading the yaml.

services?: Record<string, Services>
commands?: Commands { ready, start, stop }
ready?: string

ready is an optional command that is run repeatedly until it exits with a zero exit code. If set, the service will first go into a Starting phase, and then into a Running phase once the ready command exits with a zero exit code.

start?: string

start is the command to start and run the service. If start exits, the service will transition to the following phase:

  • Stopped: if the exit code is 0
  • Failed: if the exit code is not 0 If the stop command is not set, the start command will receive a SIGTERM signal when the service is requested to stop. If it does not exit within 2 minutes, it will receive a SIGKILL signal.
minLength1
stop?: string

stop is an optional command that runs when the service is requested to stop. If set, instead of sending a SIGTERM signal to the start command, the stop command will be run. Once the stop command exits, the start command will receive a SIGKILL signal. If the stop command exits with a non-zero exit code, the service will transition to the Failed phase. If the stop command does not exit within 2 minutes, a SIGKILL signal will be sent to both the start and stop commands.

description?: string
name?: string
minLength1
role?: "" | "default" | "editor" | "ai-agent"
One of the following:
""
"default"
"editor"
"ai-agent"
runsOn?: RunsOn { docker, machine }
docker?: Docker { environment, image }
environment?: Array<string>
image?: string
minLength1
machine?: unknown

Machine runs the service/task directly on the VM/machine level.

triggeredBy?: Array<"manual" | "postEnvironmentStart" | "postDevcontainerStart" | "prebuild">
One of the following:
"manual"
"postEnvironmentStart"
"postDevcontainerStart"
"prebuild"
tasks?: Record<string, Tasks>
command?: string
minLength1
dependsOn?: Array<string>
description?: string
name?: string
minLength1
runsOn?: RunsOn { docker, machine }
docker?: Docker { environment, image }
environment?: Array<string>
image?: string
minLength1
machine?: unknown

Machine runs the service/task directly on the VM/machine level.

triggeredBy?: Array<"manual" | "postEnvironmentStart" | "postDevcontainerStart" | "prebuild">
One of the following:
"manual"
"postEnvironmentStart"
"postDevcontainerStart"
"prebuild"
environmentId?: string
formatuuid
ReturnsExpand Collapse
AutomationUpsertResponse { updatedServiceIds, updatedTaskIds }
updatedServiceIds?: Array<string>
updatedTaskIds?: Array<string>

UpsertAutomationsFile

import Gitpod from '@gitpod/sdk';

const client = new Gitpod({
  bearerToken: process.env['GITPOD_API_KEY'], // This is the default and can be omitted
});

const response = await client.environments.automations.upsert({
  automationsFile: {
    services: {
      'web-server': {
        commands: { ready: 'curl -s http://localhost:3000', start: 'npm run dev' },
        description: 'Development web server',
        name: 'Web Server',
        triggeredBy: ['postDevcontainerStart'],
      },
    },
    tasks: {
      build: {
        command: 'npm run build',
        description: 'Builds the project artifacts',
        name: 'Build Project',
        triggeredBy: ['postEnvironmentStart'],
      },
    },
  },
  environmentId: '07e03a28-65a5-4d98-b532-8ea67b188048',
});

console.log(response.updatedServiceIds);
{
  "updatedServiceIds": [
    "string"
  ],
  "updatedTaskIds": [
    "string"
  ]
}
Returns Examples
{
  "updatedServiceIds": [
    "string"
  ],
  "updatedTaskIds": [
    "string"
  ]
}