Skip to content
Ona Docs

UpsertAutomationsFile

client.Environments.Automations.Upsert(ctx, body) (*EnvironmentAutomationUpsertResponse, error)
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 EnvironmentAutomationUpsertParams
AutomationsFile param.Field[AutomationsFile]Optional

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.

EnvironmentID param.Field[string]Optional
formatuuid
ReturnsExpand Collapse
type EnvironmentAutomationUpsertResponse struct{…}
UpdatedServiceIDs []stringOptional
UpdatedTaskIDs []stringOptional

UpsertAutomationsFile

package main

import (
  "context"
  "fmt"

  "github.com/gitpod-io/gitpod-sdk-go"
  "github.com/gitpod-io/gitpod-sdk-go/option"
)

func main() {
  client := gitpod.NewClient(
    option.WithBearerToken("My Bearer Token"),
  )
  response, err := client.Environments.Automations.Upsert(context.TODO(), gitpod.EnvironmentAutomationUpsertParams{
    AutomationsFile: gitpod.F(gitpod.AutomationsFileParam{
      Services: gitpod.F(map[string]gitpod.AutomationsFileServiceParam{
      "web-server": gitpod.AutomationsFileServiceParam{
        Commands: gitpod.F(gitpod.AutomationsFileServicesCommandsParam{
          Ready: gitpod.F("curl -s http://localhost:3000"),
          Start: gitpod.F("npm run dev"),
        }),
        Description: gitpod.F("Development web server"),
        Name: gitpod.F("Web Server"),
        TriggeredBy: gitpod.F([]gitpod.AutomationsFileServicesTriggeredBy{gitpod.AutomationsFileServicesTriggeredByPostDevcontainerStart}),
      },
      }),
      Tasks: gitpod.F(map[string]gitpod.AutomationsFileTaskParam{
      "build": gitpod.AutomationsFileTaskParam{
        Command: gitpod.F("npm run build"),
        Description: gitpod.F("Builds the project artifacts"),
        Name: gitpod.F("Build Project"),
        TriggeredBy: gitpod.F([]gitpod.AutomationsFileTasksTriggeredBy{gitpod.AutomationsFileTasksTriggeredByPostEnvironmentStart}),
      },
      }),
    }),
    EnvironmentID: gitpod.F("07e03a28-65a5-4d98-b532-8ea67b188048"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.UpdatedServiceIDs)
}
{
  "updatedServiceIds": [
    "string"
  ],
  "updatedTaskIds": [
    "string"
  ]
}
Returns Examples
{
  "updatedServiceIds": [
    "string"
  ],
  "updatedTaskIds": [
    "string"
  ]
}