tasks
in the .gitpod.yml
configuration file.
before
: Preparatory steps that should run before the main setup, such as setting up tools or permissions.init
: Long running processes that setup the project and workspace file system, like downloading dependencies and building code.command
: Commands that start your main application or services.Caveats
- Any file changes made outside of
/workspace
file hierarchy frominit
tasks will be lost on workspace start when prebuilds are enabled. Learn more- User specific environment variables are not loaded automatically for
init
andbefore
tasks but can be loaded if you want. Learn more
gp validate
or gp validate --prebuild
to test in a debug workspace. The debug workspace runs as a container within your workspace and shares its file system.
gp validate
will incur an image build. After which, iteration is quick because docker images have been pulled and built./workspace
content. For example, if Tasks mutate state or consume freespace, as you iterate, reset state or delete files in /workspace
as needed. For example, state could be programs you build, test harness output, or cached docker images.before
and init
tasks. Workspaces are then created based on the result of the most recent prebuild, which allows for faster workspace startup times.
The init
task is where you want to do things like:
init
tasks can be re-run on the same file-system state under certain conditions (cmp. Prebuild: Incremental), so they should be idempotent: no matter how often they are triggered, they should return the same result.before
or init
tasks will always trigger a new prebuild. See Use of prebuilds for more information.init
tasks continuously behind the scene so you and anyone who opens your project on Gitpod doesn’t have to wait.before
, init
and command
are executed in that order.
New workspace - no prebuild
before
and command
tasks are executed: init
already ran as part of the prebuild.
New workspace - prebuild with same commit
before
, init
(!) and command
are executed.
New workspace - prebuild with later commit
init
is executed like on a regular workspace startup, the execution should still be way faster: Caches are pre-fetched, external dependencies downloaded, and almost all build systems support incremental builds.init
task (see above) either as part of a prebuild or when you started the workspace for the first time.
As part of a workspace restart, Gitpod executes the before
and command
tasks:
Restart a workspace
init
task (see above) either as part of a prebuild or when you or a team member started the snapshot’s initial workspace for the first time.
As part of starting a snapshot, Gitpod executes the before
and command
tasks:
Start a snapshot
openMode
properties below.
Please note that this information is used if no previous terminals in the layout exist.
Snapshots will first try to reuse existing terminals in the layout, before opening new ones.
openMode | Description |
---|---|
openMode: tab-after | Opens in the same tab group right after the previous tab |
openMode: tab-before | Opens in the same tab group left before the previous tab |
openMode: split-right | Splits and adds the terminal to the right |
openMode: split-left | Splits and adds the terminal to the left |
openMode: split-top | Deprecated. Splits and adds the terminal to the top |
openMode: split-bottom | Deprecated. Splits and adds the terminal to the bottom |
Note:before
andinit
tasks need to terminate whilecommand
can run indefinitely (i.e. until cancelled with Ctrl + C). This is becausebefore
andinit
may run as part of a prebuild and if these tasks do not terminate, the prebuild will eventually fail with a timeout.
npm
command. The init
task terminates once the dependencies are installed while the command
task starts a development server and does not terminate.
|
notation where each line below (make sure you indent correctly) runs in sequence once the previous command terminates.
In the following example, the init
task installs dependencies and configures a database. Then, the command
task starts the dev server(s).
Note: In case of multiple terminals, there is no guarantee on the order in which tasks execute. The only guarantee you have is thatbefore
,init
andcommand
execute in that sequence per terminal.
npm install
in the example above fails, the npm run configure-database
will still run. See how to exit after failure below for a workaround.gp sync-await
and gp sync-done
.
http://localhost:3000
.
You can achieve this with two terminals and the gp ports await
CLI command.
tasks
inside separate bash
($SHELL
) shells. Gitpod can only assert the exit status of the shell process of a task. Normally bash
or other shells don’t halt on a failure of a command unless you explicitly ask it to. bash
only inherits the last exit status of a script run with it before it’s own exit
. Hence Gitpod can’t determine if all of your commands inside the init
task succeeded. To have that effect, you can put set -e;
on top of task shell-commands and wrap your whole task-script with ()
to configure that particular task shell to halt and immediately exit with an error code for a failure of any command. This can be specially helpful for prebuilds (i.e init
tasks)
.gitpod.yml
configuration. Consider the following example where tasks are defined within a single terminal session:
.gitpod.yml
configuration:
before
, init
, and command
steps in one terminal, each task runs in a separate terminal in parallel. This approach is sometimes desired, and in such cases, you might also be interested in our gp sync-await command.