## UpdateEnvironment `client.Environments.Update(ctx, body) (*EnvironmentUpdateResponse, error)` **post** `/gitpod.v1.EnvironmentService/UpdateEnvironment` Updates an environment's configuration while it is running. Updates are limited to: - Git credentials (username, email) - SSH public keys - Content initialization - Port configurations - Automation files - Environment timeouts ### Examples - Update Git credentials: Updates the Git configuration for the environment. ```yaml environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048" spec: content: gitUsername: "example-user" gitEmail: "user@example.com" ``` - Add SSH public key: Adds a new SSH public key for authentication. ```yaml environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048" spec: sshPublicKeys: - id: "0194b7c1-c954-718d-91a4-9a742aa5fc11" value: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI..." ``` - Update content session: Updates the content session identifier for the environment. ```yaml environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048" spec: content: session: "0194b7c1-c954-718d-91a4-9a742aa5fc11" ``` Note: Machine class changes require stopping the environment and creating a new one. ### Parameters - `body EnvironmentUpdateParams` - `EnvironmentID param.Field[string]` environment_id specifies which environment should be updated. +required - `Metadata param.Field[EnvironmentUpdateParamsMetadata]` - `Name string` name is the user-defined display name of the environment - `Spec param.Field[EnvironmentUpdateParamsSpec]` - `AutomationsFile EnvironmentUpdateParamsSpecAutomationsFile` automations_file is the automations file spec of the environment - `AutomationsFilePath string` automations_file_path is the path to the automations file that is applied in the environment, relative to the repo root. path must not be absolute (start with a /): ``` this.matches('^$|^[^/].*') ``` - `Session string` - `Content EnvironmentUpdateParamsSpecContent` - `GitEmail string` The Git email address - `GitUsername string` The Git username - `Initializer EnvironmentInitializer` initializer configures how the environment is to be initialized - `Specs []EnvironmentInitializerSpec` - `ContextURL EnvironmentInitializerSpecsContextURL` - `URL string` url is the URL from which the environment is created - `Git EnvironmentInitializerSpecsGit` - `CheckoutLocation string` a path relative to the environment root in which the code will be checked out to - `CloneTarget string` the value for the clone target mode - use depends on the target mode - `RemoteUri string` remote_uri is the Git remote origin - `TargetMode EnvironmentInitializerSpecsGitTargetMode` the target mode determines what gets checked out - `const EnvironmentInitializerSpecsGitTargetModeCloneTargetModeUnspecified EnvironmentInitializerSpecsGitTargetMode = "CLONE_TARGET_MODE_UNSPECIFIED"` - `const EnvironmentInitializerSpecsGitTargetModeCloneTargetModeRemoteHead EnvironmentInitializerSpecsGitTargetMode = "CLONE_TARGET_MODE_REMOTE_HEAD"` - `const EnvironmentInitializerSpecsGitTargetModeCloneTargetModeRemoteCommit EnvironmentInitializerSpecsGitTargetMode = "CLONE_TARGET_MODE_REMOTE_COMMIT"` - `const EnvironmentInitializerSpecsGitTargetModeCloneTargetModeRemoteBranch EnvironmentInitializerSpecsGitTargetMode = "CLONE_TARGET_MODE_REMOTE_BRANCH"` - `const EnvironmentInitializerSpecsGitTargetModeCloneTargetModeLocalBranch EnvironmentInitializerSpecsGitTargetMode = "CLONE_TARGET_MODE_LOCAL_BRANCH"` - `const EnvironmentInitializerSpecsGitTargetModeCloneTargetModeRemoteTag EnvironmentInitializerSpecsGitTargetMode = "CLONE_TARGET_MODE_REMOTE_TAG"` - `UpstreamRemoteUri string` upstream_Remote_uri is the fork upstream of a repository - `Session string` session should be changed to trigger a content reinitialization - `Devcontainer EnvironmentUpdateParamsSpecDevcontainer` - `DevcontainerFilePath string` devcontainer_file_path is the path to the devcontainer file relative to the repo root path must not be absolute (start with a /): ``` this.matches('^$|^[^/].*') ``` - `Session string` session should be changed to trigger a devcontainer rebuild - `KernelControlsConfig KernelControlsConfig` kernel_controls_config configures kernel-level controls for this environment - `Veto Veto` veto controls blocking mechanisms - `Exec VetoExec` exec controls executable blocking - `Action KernelControlsAction` action specifies what action kernel-level controls take on policy violations - `const KernelControlsActionUnspecified KernelControlsAction = "KERNEL_CONTROLS_ACTION_UNSPECIFIED"` - `const KernelControlsActionBlock KernelControlsAction = "KERNEL_CONTROLS_ACTION_BLOCK"` - `const KernelControlsActionAudit KernelControlsAction = "KERNEL_CONTROLS_ACTION_AUDIT"` - `Denylist []string` denylist is the list of executable paths or names to block - `Enabled bool` enabled controls whether executable blocking is active - `Ports []EnvironmentUpdateParamsSpecPort` ports controls port sharing - `Admission AdmissionLevel` policy of this port - `const AdmissionLevelUnspecified AdmissionLevel = "ADMISSION_LEVEL_UNSPECIFIED"` - `const AdmissionLevelOwnerOnly AdmissionLevel = "ADMISSION_LEVEL_OWNER_ONLY"` - `const AdmissionLevelEveryone AdmissionLevel = "ADMISSION_LEVEL_EVERYONE"` - `const AdmissionLevelOrganization AdmissionLevel = "ADMISSION_LEVEL_ORGANIZATION"` - `const AdmissionLevelCreatorOnly AdmissionLevel = "ADMISSION_LEVEL_CREATOR_ONLY"` - `Name string` name of this port - `Port int64` port number - `Protocol EnvironmentUpdateParamsSpecPortsProtocol` protocol for communication (Gateway proxy → user environment service). this setting only affects the protocol used between Gateway and user environment services. - `const EnvironmentUpdateParamsSpecPortsProtocolProtocolUnspecified EnvironmentUpdateParamsSpecPortsProtocol = "PROTOCOL_UNSPECIFIED"` - `const EnvironmentUpdateParamsSpecPortsProtocolProtocolHTTP EnvironmentUpdateParamsSpecPortsProtocol = "PROTOCOL_HTTP"` - `const EnvironmentUpdateParamsSpecPortsProtocolProtocolHTTPS EnvironmentUpdateParamsSpecPortsProtocol = "PROTOCOL_HTTPS"` - `SSHPublicKeys []EnvironmentUpdateParamsSpecSSHPublicKey` ssh_public_keys are the public keys to update empty array means nothing to update - `ID string` id is the unique identifier of the public key - `Value string` value is the actual public key in the public key file format if not provided, the public key will be removed - `Timeout EnvironmentUpdateParamsSpecTimeout` Timeout configures the environment timeout - `Disconnected string` inacitivity is the maximum time of disconnection before the environment is stopped or paused. Minimum duration is 30 minutes. Set to 0 to disable. value must be 0s (disabled) or at least 1800s (30 minutes): ``` this == duration('0s') || this >= duration('1800s') ``` ### Returns - `type EnvironmentUpdateResponse interface{…}` ### 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"), ) environment, err := client.Environments.Update(context.TODO(), gitpod.EnvironmentUpdateParams{ EnvironmentID: gitpod.F("07e03a28-65a5-4d98-b532-8ea67b188048"), Spec: gitpod.F(gitpod.EnvironmentUpdateParamsSpec{ SSHPublicKeys: gitpod.F([]gitpod.EnvironmentUpdateParamsSpecSSHPublicKey{gitpod.EnvironmentUpdateParamsSpecSSHPublicKey{ ID: gitpod.F("0194b7c1-c954-718d-91a4-9a742aa5fc11"), Value: gitpod.F("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI..."), }}), }), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", environment) } ``` #### Response ```json {} ```