Environment

Drone provides the ability to define environment variables scoped to individual build steps. Example pipeline step with custom environment variables:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
kind: pipeline
type: ssh
name: default

server:
  host: 1.2.3.4
  user: root
  password:
    from_secret: password

steps:
- name: build
  commands:
  - go build
  - go test
  environment:
    GOOS: linux
    GOARCH: amd64

Drone automatically injects environment variables containing repository and commit metadata into each pipeline step. See the environment variable index for a full list of variables.

Environment Variables /configuration/variables

Secrets

Drone provides the ability to source environment variables from secrets. In the below example we provide the username and password as environment variables to the step.

 5
 6
 7
 8
 9
10
11
12
13
14
15
steps:
- name: build
  commands:
  - docker login -u $USERNAME -p $PASSWORD
  - docker build -t hello-world .
  - docker push hello-world
  environment:
    PASSWORD:
      from_secret: password
    USERNAME:
      from_secret: username

Common Problems

Please note ${variable} expressions are subject to pre-processing. If you do not want the pre-processor to evaluate your expression it must be escaped.

5
6
7
8
9
10
11
steps:
- name: build
  commands:
  - echo $GOOS
  - echo $${GOARCH}
  - go build
  - go test

Please also note the environment section cannot expand environment variables or evaluate shell expressions. If you need to construct variables it should be done in the commands section.

5
6
7
8
9
10
steps:
- name: build
  commands:
  - export GOPATH=$HOME/golang
  - go build
  - go test