Creating Tasks and Services
To create a dynamic tasks and services, use the Gitpod CLI to generate or obtain the tasks and services configuration and pipe it directly into thegitpod automations update - command. Notice the - at the end which signals that we want to read the tasks and services from stdin.
When generating tasks and services, keep in mind that their IDs can only contain alphanumeric characters, underscores, and hyphens, and must be between 1 and 128 characters long.Basic example:
Example uses
-
Exposing Package Scripts: Create tasks from scripts in a
package.jsonfile:This example usesgsubto ensure all task IDs comply with the required format. -
Dynamic Service Creation: Create services for components in a specific directory:
Suppose you have a
componentsdirectory which contains a set of Go components. The following command creates services for each of those components. -
Remote Tasks and Services Configuration: Download and apply tasks and services from a remote source:
Only ever download tasks and services from sources you trust; better yet, verify the integrity of the tasks and services file before applying it.
Make sure that the remote configuration file uses compliant task and service IDs.
Interacting with Dynamic Tasks and Services from Outside an Environment
One of Gitpod’s most powerful features is the ability to interact with and control tasks and services from outside the environment itself. This capability, combined with Gitpod’s environment management features, transforms Gitpod into a flexible automation and execution platform. You can orchestrate complex workflows and tasks without needing to be actively connected to an environment. When interacting with tasks and services from outside an environment, you can perform the same operations as from within an environment:- Execute Tasks: Start, monitor, and manage automation tasks in remote environments.
- Control Services: Start, stop, and manage long-running automation services.
- Access Logs: Retrieve and monitor logs from tasks and services running in the environment.
- Update tasks and services: Modify tasks and services configurations for environments on the fly.
Example Workflow: Create, Execute Automation, and Clean Up
Here’s a concrete example of how you might use these capabilities along with Gitpod’s environment management to create an environment, run an automation task, and then clean up:- Create a new environment based on a Git repository.
- Start a specific automation task (in this case, ‘build-and-test’) in that environment.
- Stream the logs of the automation task to monitor its progress.
- Check the final status of the automation task.
- Based on the task’s outcome, either clean up the environment or leave it running for further investigation.
Benefits of External Automation Control
- CI/CD Integration: Easily integrate Gitpod tasks and services into your existing CI/CD pipelines.
- Batch Processing: Set up and run multiple automation tasks across different environments in parallel for large-scale operations.
- Automated Testing: Create ephemeral environments for running automated test suites without manual intervention.
- Resource Optimization: Run tasks and services in environments only when needed and automatically clean them up after use.