Adding commands to a devfile

A devfile allows 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.

Procedure
  1. Add a commands section in the devfile, containing a list of one or more commands.

  2. For each command, define an unique value for the mandatory id attribute.

  3. For each command, define a mandatory type of one of the following types:

    • exec

    • apply

    • composite

    • vscode-tasks

    Sample command
     commands:
       - id: build
         exec:
          component: mysql
          commandLine: mvn clean
          workingDir: /projects/spring-petclinic
  4. 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.

  5. 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
  6. 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 the parallel 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
Additional resources