## 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. ```yaml 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 ``` ### Parameters - `body EnvironmentAutomationUpsertParams` - `AutomationsFile param.Field[AutomationsFile]` 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]` ### Returns - `type EnvironmentAutomationUpsertResponse struct{…}` - `UpdatedServiceIDs []string` - `UpdatedTaskIDs []string` ### Example ```go 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) } ``` #### Response ```json { "updatedServiceIds": [ "string" ], "updatedTaskIds": [ "string" ] } ```