Skip to content
Ona Docs

CreateTask

client.Environments.Automations.Tasks.New(ctx, body) (*EnvironmentAutomationTaskNewResponse, error)
POST/gitpod.v1.EnvironmentAutomationService/CreateTask

Creates a new automation task.

Use this method to:

  • Define one-off or scheduled tasks
  • Set up build or test automation
  • Configure task dependencies
  • Specify execution environments

Examples

  • Create basic task:

    Creates a simple build task.

    environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048"
    metadata:
      reference: "build"
      name: "Build Project"
      description: "Builds the project artifacts"
      triggeredBy:
        - postEnvironmentStart: true
    spec:
      command: "npm run build"
  • Create task with dependencies:

    Creates a task that depends on other services.

    environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048"
    metadata:
      reference: "test"
      name: "Run Tests"
      description: "Runs the test suite"
    spec:
      command: "npm test"
    dependsOn: ["d2c94c27-3b76-4a42-b88c-95a85e392c68"]
ParametersExpand Collapse
body EnvironmentAutomationTaskNewParams
DependsOn param.Field[[]string]Optional
EnvironmentID param.Field[string]Optional
formatuuid
Metadata param.Field[TaskMetadata]Optional
Spec param.Field[TaskSpec]Optional
ReturnsExpand Collapse
type EnvironmentAutomationTaskNewResponse struct{…}
Task Task
ID string
formatuuid
DependsOn []stringOptional

dependencies specifies the IDs of the automations this task depends on.

EnvironmentID stringOptional
formatuuid
Metadata TaskMetadataOptional
CreatedAt TimeOptional

created_at is the time the task was created.

formatdate-time
Creator SubjectOptional

creator describes the principal who created the task.

ID stringOptional

id is the UUID of the subject

formatuuid
Principal PrincipalOptional

Principal is the principal of the subject

One of the following:
const PrincipalUnspecified Principal = "PRINCIPAL_UNSPECIFIED"
const PrincipalAccount Principal = "PRINCIPAL_ACCOUNT"
const PrincipalUser Principal = "PRINCIPAL_USER"
const PrincipalRunner Principal = "PRINCIPAL_RUNNER"
const PrincipalEnvironment Principal = "PRINCIPAL_ENVIRONMENT"
const PrincipalServiceAccount Principal = "PRINCIPAL_SERVICE_ACCOUNT"
const PrincipalRunnerManager Principal = "PRINCIPAL_RUNNER_MANAGER"
Description stringOptional

description is a user-facing description for the task. It can be used to provide context and documentation for the task.

Name stringOptional

name is a user-facing name for the task. Unlike the reference, this field is not unique, and not referenced by the system. This is a short descriptive name for the task.

minLength1
Reference stringOptional

reference is a user-facing identifier for the task which must be unique on the environment. It is used to express dependencies between tasks, and to identify the task in user interactions (e.g. the CLI).

TriggeredBy []AutomationTriggerOptional

triggered_by is a list of trigger that start the task.

BeforeSnapshot boolOptional
Manual boolOptional
PostDevcontainerStart boolOptional
PostEnvironmentStart boolOptional
PostMachineStart boolOptional
Prebuild boolOptional
Spec TaskSpecOptional
Command stringOptional

command contains the command the task should execute

env specifies environment variables for the task.

Name stringOptional

name is the environment variable name.

minLength1
Value stringOptional

value is a literal string value.

ValueFrom EnvironmentVariableSourceOptional

value_from specifies a source for the value.

SecretRef SecretRef

secret_ref references a secret by ID.

ID stringOptional

id is the UUID of the secret to reference.

formatuuid
PrebuildRequiresSuccess boolOptional

prebuild_requires_success controls whether a non-successful outcome of this task should fail the prebuild. When true and the task is triggered by a prebuild or before_snapshot trigger, any terminal phase other than SUCCEEDED (i.e. FAILED or STOPPED) will cause the prebuild to fail instead of just recording a warning. Defaults to false (existing behavior: task failures produce warnings only).

RunsOn RunsOnOptional

runs_on specifies the environment the task should run on.

Docker RunsOnDockerOptional
Environment []stringOptional
Image stringOptional
minLength1
Machine unknownOptional

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

CreateTask

package main

import (
  "context"
  "fmt"

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

func main() {
  client := gitpod.NewClient(
    option.WithBearerToken("My Bearer Token"),
  )
  task, err := client.Environments.Automations.Tasks.New(context.TODO(), gitpod.EnvironmentAutomationTaskNewParams{
    EnvironmentID: gitpod.F("07e03a28-65a5-4d98-b532-8ea67b188048"),
    Metadata: gitpod.F(shared.TaskMetadataParam{
      Description: gitpod.F("Builds the project artifacts"),
      Name: gitpod.F("Build Project"),
      Reference: gitpod.F("build"),
      TriggeredBy: gitpod.F([]shared.AutomationTriggerParam{shared.AutomationTriggerParam{
        PostEnvironmentStart: gitpod.F(true),
      }}),
    }),
    Spec: gitpod.F(shared.TaskSpecParam{
      Command: gitpod.F("npm run build"),
    }),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", task.Task)
}
{
  "task": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
    "dependsOn": [
      "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
    ],
    "environmentId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
    "metadata": {
      "createdAt": "2019-12-27T18:11:19.117Z",
      "creator": {
        "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
        "principal": "PRINCIPAL_UNSPECIFIED"
      },
      "description": "description",
      "name": "x",
      "reference": "reference",
      "triggeredBy": [
        {
          "beforeSnapshot": true,
          "manual": true,
          "postDevcontainerStart": true,
          "postEnvironmentStart": true,
          "postMachineStart": true,
          "prebuild": true
        }
      ]
    },
    "spec": {
      "command": "command",
      "env": [
        {
          "name": "x",
          "value": "value",
          "valueFrom": {
            "secretRef": {
              "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
            }
          }
        }
      ],
      "prebuildRequiresSuccess": true,
      "runsOn": {
        "docker": {
          "environment": [
            "string"
          ],
          "image": "x"
        },
        "machine": {}
      }
    }
  }
}
Returns Examples
{
  "task": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
    "dependsOn": [
      "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
    ],
    "environmentId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
    "metadata": {
      "createdAt": "2019-12-27T18:11:19.117Z",
      "creator": {
        "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
        "principal": "PRINCIPAL_UNSPECIFIED"
      },
      "description": "description",
      "name": "x",
      "reference": "reference",
      "triggeredBy": [
        {
          "beforeSnapshot": true,
          "manual": true,
          "postDevcontainerStart": true,
          "postEnvironmentStart": true,
          "postMachineStart": true,
          "prebuild": true
        }
      ]
    },
    "spec": {
      "command": "command",
      "env": [
        {
          "name": "x",
          "value": "value",
          "valueFrom": {
            "secretRef": {
              "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
            }
          }
        }
      ],
      "prebuildRequiresSuccess": true,
      "runsOn": {
        "docker": {
          "environment": [
            "string"
          ],
          "image": "x"
        },
        "machine": {}
      }
    }
  }
}