Adding commands to a devfile
A devfile allows you to specify commands to be available for execution in a workspace. Every command can contain a subset of actions. These subsets are related to specific components and are executed in the component containers. See the following tables for command properties in a devfile:
Key | Type | Required | Description |
---|---|---|---|
exec |
execObject |
no |
The exec command to run. |
composite |
compositeObject |
no |
The composite command to run. |
Key | Type | Required | Description |
---|---|---|---|
id |
string |
yes |
The ID of the command. |
commandLine |
string |
yes |
The command to run. |
component |
string |
no |
The component to which the action relates. |
label |
string |
no |
The optional label to describe the command. |
workingDir |
string |
no |
The working directory where you execute the command. |
group |
groupObject |
no |
The group to which the command belongs. |
environment |
envObject |
no |
The list of environment variables you use. |
Key | Type | Required | Description |
---|---|---|---|
id |
string |
yes |
The ID of the command. |
commands |
string |
no |
The exec commands that constitute the composite command and chains multiple commands together. |
parallel |
boolean |
no |
The flag that indicates if commands are executed in parallel. |
label |
string |
no |
The optional label to describe the command. |
group |
groupObject |
no |
The group to which the composite command belongs. The composite command cannot be of the |
Key | Type | Required | Description |
---|---|---|---|
kind |
string |
yes |
The group to which the command belongs, such as: |
isDefault |
boolean |
no |
Identifies if it is the default command to run. Only one default command can be defined for each group. |
-
Add a
commands
section in the devfile, containing a list of one or more commands. -
For each command, define an unique value for the mandatory
id
attribute. -
For each command, define a mandatory type of one of the following types:
-
exec
-
apply
-
composite
Sample commandcommands: - id: build exec: component: mysql commandLine: mvn clean workingDir: /projects/spring-petclinic
-
-
Define attributes for the
exec
command to run using the default shell in the container.-
A
commandLine
attribute that is a command to execute. -
A
component
attribute that specifies the container in which to execute the command.
schemaVersion: 2.1.0 metadata: name: mydevfile projects: - name: my-go-project clonePath: go/src/github.com/acme/my-go-project git: remotes: origin: "https://github.com/acme/my-go-project.git" components: - name: go-cli container: image: golang memoryLimit: 512Mi mountSources: true command: ['sleep', 'infinity'] env: - name: GOPATH value: $(PROJECTS_ROOT)/go - name: GOCACHE value: /tmp/go-cache commands: - id: compile and run exec: component: go-cli commandLine: "go get -d && go run main.go" workingDir: "${PROJECTS_ROOT}/src/github.com/acme/my-go-project"
-
A command can have only one action, though you can use
composite
commands to execute several commands either sequentially or in parallel.
-
-
Command group
To assign a given command to one or more groups that represent the nature of the command, use the following supported group types:
-
build
-
run
-
test
-
debug
For each of the groups, define one default command by specifying the
isDefault
value.schemaVersion: 2.1.0 metadata: name: mydevfile projects: - name: my-maven-project clonePath: maven/src/github.com/acme/my-maven-project git: remotes: origin: "https://github.com/acme/my-maven-project.git" components: - name: maven container: image: eclipse/maven-jdk8:latest mountSources: true command: ['tail'] commands: - id: package exec: component: maven commandLine: "mvn package" group: kind: build - id: install exec: component: maven commandLine: "mvn install" group: kind: build isDefault: true
-
-
Composite command
To chain multiple commands together, define a composite command. To reference the individual commands that are called from a composite command, use the
name
of the command. To specify whether commands within a composite command are to be executed sequentially or in parallel, define theparallel
boolean.schemaVersion: 2.1.0 metadata: name: mydevfile projects: - name: my-maven-project clonePath: maven/src/github.com/acme/my-maven-project git: remotes: origin: "https://github.com/acme/my-maven-project.git" components: - name: maven container: image: eclipse/maven-jdk8:latest mountSources: true command: ['tail'] commands: - id: package exec: component: maven commandLine: "mvn package" group: kind: build - id: install exec: component: maven commandLine: "mvn install" group: kind: build isDefault: true - id: installandpackage composite: commands: - install - package parallel: false