You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the current version being used to run the build. Whether or not they're set
213
-
depends on the language you're using.
214
-
215
-
*`TRAVIS_GO_VERSION`
216
-
*`TRAVIS_JDK_VERSION`
217
-
*`TRAVIS_JULIA_VERSION`
218
-
*`TRAVIS_NODE_VERSION`
219
-
*`TRAVIS_OTP_RELEASE`
220
-
*`TRAVIS_PERL_VERSION`
221
-
*`TRAVIS_PHP_VERSION`
222
-
*`TRAVIS_PYTHON_VERSION`
223
-
*`TRAVIS_RUBY_VERSION`
224
-
*`TRAVIS_RUST_VERSION`
225
-
*`TRAVIS_SCALA_VERSION`
226
-
227
-
The following environment variables are available for Objective-C builds.
228
-
229
-
*`TRAVIS_XCODE_SDK`
230
-
*`TRAVIS_XCODE_SCHEME`
231
-
*`TRAVIS_XCODE_PROJECT`
232
-
*`TRAVIS_XCODE_WORKSPACE`
171
+
There is a [list of default environment variables](/user/environment-variables#Default-Environment-Variables) available in each build environment.
233
172
234
173
### Libraries
235
174
236
175
* OpenSSL
237
176
* ImageMagick
238
177
239
-
240
178
### apt configuration
241
179
242
180
apt is configured to not require confirmation (assume -y switch by default) using both `DEBIAN_FRONTEND` env variable and apt configuration file. This means `apt-get install -qq` can be used without the -y flag.
Copy file name to clipboardExpand all lines: user/environment-variables.md
+120-61
Original file line number
Diff line number
Diff line change
@@ -4,44 +4,43 @@ layout: en
4
4
permalink: /user/environment-variables/
5
5
---
6
6
7
-
A common way to customize the build process is to use environment variables. These can be accessed from any stage in your build process.
7
+
A common way to customize the build process is to use environment variables, which can be accessed from any stage in your build process.
8
8
9
9
<divid="toc"></div>
10
10
11
-
## Where to define variables
11
+
* Variables defined in [.travis.yml](#Defining-Variables-in-.travis.yml) are tied to a certain commit. Changing them requires a new commit, restarting an old build uses the old values. They are also available automatically on forks of the repository. Define variables in `.travis.yml` that:
12
12
13
-
Travis CI offers two different places for defining environment variables: In the [.travis.yml](#Variables-in-the-.travis.yml) or using the [repository settings](#Using-Settings). These differ slightly in their scope.
13
+
+ are needed for the build to run and that don't contain sensitive data. For instance, a test suite for a Ruby application might require `$RACK_ENV` to be set to `test`.
14
+
+ differ per branch.
15
+
+ differ per job.
14
16
15
-
Variables in the **.travis.yml** are bound to a certain commit. Changing them requires a new commit, restarting an old build will use the old values. They will also be available automatically on forks of the repository.
17
+
*Variables defined in [repository settings](#Defining-Variables-in-Repository-Settings) are the same for all builds. When you restart an old build, it uses the latest values. These variables are not automatically available to forks. Define variables in the Repository Settings that:
16
18
17
-
On the other hand, variables defined in the **repository settings** are the same for all builds. When you restart an old build, it will use the latest values. These variables are not automatically available to forks.
19
+
+ differ per repository.
20
+
+ contain sensitive data, such as third-party credentials.
18
21
19
-
Keep this in mind when choosing where to store which variable.
22
+
* Use [Encrypted variables](#Encrypted-Variables) for sensitive data such as authentication tokens.
20
23
21
-
Examples for using the **.travis.yml**:
24
+
> If you define a variable with the same name in `.travis.yml` and in the Repository Settings, the one in `.travis.yml` takes precedence. If you define a variable as both encrypted and unencrypted, the one defined later in the file takes precedence.
22
25
23
-
* Variables generally needed for the build to run, that don't contain sensitive data. For instance, a test suite for a Ruby application might require `$RACK_ENV` to be set to `test`.
24
-
* Variables that have to differ per branch.
25
-
* Variables that have to [differ per job](#Matrix-Variables).
26
+
There is also a [complete list of default environment variables](#Default-Environment-Variables) which are present in all Travis CI environments.
26
27
27
-
Examples for using **repository settings**:
28
+
## Defining Variables in .travis.yml
28
29
29
-
* Variables that have to differ per repository.
30
-
* Variables that contain sensitive data, such as third-party credentials.
30
+
To define an environment variable in your `.travis.yml`, add the `env` line, for example:
31
31
32
-
If you define a variable with the same name in both places, the one from the .travis.yml will override the one from the repository settings.
33
-
34
-
## Variables in the `.travis.yml`
35
-
36
-
To specify an environment variable in your `.travis.yml`, add the following line:
37
-
38
-
env: DB=postgres
32
+
env:
33
+
- DB=postgres
39
34
40
-
Environment variables are useful for configuring build scripts. See the example in [Database setup](/user/database-setup/#multiple-database-systems).
35
+
> Note that environment variable values may need quoting. For example, if they have asterisks (`*`) in them:
36
+
> ````
37
+
> env:
38
+
> PACKAGE_VERSION="1.0.*"
39
+
> ````
41
40
42
-
### Matrix Variables
41
+
### Defining Multiple Variables per Item
43
42
44
-
You can specify more than one environment variable per item in the `env` array:
43
+
When you specify multiple variables per item in the `env` array (matrix variables), one build is triggered per item.
45
44
46
45
rvm:
47
46
- 1.9.3
@@ -50,21 +49,17 @@ You can specify more than one environment variable per item in the `env` array:
50
49
- FOO=foo BAR=bar
51
50
- FOO=bar BAR=foo
52
51
53
-
With this configuration, **4 individual builds** will be triggered:
52
+
this configuration triggers **4 individual builds**:
54
53
55
54
1. Ruby 1.9.3 with `FOO=foo` and `BAR=bar`
56
55
2. Ruby 1.9.3 with `FOO=bar` and `BAR=foo`
57
-
3. Rubinius in 1.8 mode with `FOO=foo` and `BAR=bar`
58
-
4. Rubinius in 1.8 mode with `FOO=bar` and `BAR=foo`
56
+
3. Rubinius latest version (rbx) with `FOO=foo` and `BAR=bar`
57
+
4. Rubinius latest version (rbx) with `FOO=bar` and `BAR=foo`
59
58
60
-
Note that environment variable values may need quoting. For example, if they have asterisks (`*`) in them:
61
-
62
-
env:
63
-
- PACKAGE_VERSION="1.0.*"
64
59
65
60
### Global Variables
66
61
67
-
Sometimes you may want to use env variables that are global to the matrix, i.e. they're inserted into each matrix row. That may include keys, tokens, URIs or other data that is needed for every build. In such cases, instead of manually adding such keys to each env line in matrix, you can use `global` and `matrix` keys to differentiate between those two cases. For example:
62
+
Sometimes you may want to use environment variables that are global to the matrix, i.e. they're inserted into each matrix row. That may include keys, tokens, URIs or other data that is needed for every build. In such cases, instead of manually adding such keys to each `env` line in matrix, you can use `global` and `matrix` keys to differentiate between those two cases. For example:
68
63
69
64
env:
70
65
global:
@@ -74,65 +69,129 @@ Sometimes you may want to use env variables that are global to the matrix, i.e.
74
69
- USE_NETWORK=true
75
70
- USE_NETWORK=false
76
71
77
-
Such configuration will generate matrix with 2 following env rows:
Besides the **.travis.yml**, you can also use the **repository settings** to set an environment variable.
79
+
To define variables in Repository Settings, make sure you're logged in, navigate to the repository in question, choose "Settings" from the cog menu, and click on "Add new variable" in the "Environment Variables" section.
85
80
86
81
<figure>
87
-
[](/images/settings-env-vars.png)
88
-
<figcaption>Environment Variables in the Repository Settings]</figcaption>
82
+

83
+
<figcaption>Environment Variables in the Repository Settings</figcaption>
89
84
</figure>
90
85
86
+
By default, the value of these new environment variables is hidden from the `export` line in the logs. This corresponds to the behavior of [encrypted variables](#Encrypted-Variables) in your `.travis.yml`.
91
87
92
-
To do so, make sure you're logged in, navigate to the repository in question, choose "Settings" from the cog menu, and click on "Add new variable" in the "Environment Variables" section.
93
-
94
-
By default, the value of these new environment variables will be hidden from the `export` line in the logs. This corresponds to the behavior of [encrypted variables](#Secure-Variables) in your .travis.yml.
95
-
96
-
Similarly, we do not expose these values to untrusted builds, triggered by pull requests from another repository.
88
+
Similarly, we do not provide these values to untrusted builds, triggered by pull requests from another repository.
97
89
98
90
As an alternative to the web interface, you can also use the CLI's [`env`](https://github.com/travis-ci/travis.rb#env) command.
99
91
100
-
## Secure Variables
92
+
## Encrypted Variables
101
93
102
-
Additionally, variables can be marked "secure", which will encrypt the content and hide their value from the corresponding `export` line in the build. This can be used to expose sensitive data, like API credentials, to the Travis CI build.
94
+
Variables can be encrypted so that their content is not shown in the corresponding `export` line in the build. This is used to provide sensitive data, like API credentials, to the Travis CI build. Encrypted variables are not added to untrusted builds such as pull requests coming from another repository.
103
95
104
-
Secure variables will not be added to untrusted builds (ie, builds for pull requests coming from another repository).
105
-
106
-
### In the .travis.yml
107
-
108
-
In the previous `.travis.yml` example, one of the environment variables had a token in it. Since putting private tokens in a file in cleartext isn't always the best idea, you might want to encrypt the environment variable. This allows you to keep parts of the configuration private. A configuration with secure environment variables might look something like this:
96
+
A `.travis.yml` file containing encrypted variables looks like this:
109
97
110
98
env:
111
99
global:
112
-
- secure: <encrypted string here>
100
+
- secure: <long encrypted string here>
113
101
- TIMEOUT=1000
114
102
matrix:
115
103
- USE_NETWORK=true
116
104
- USE_NETWORK=false
117
105
- secure: <you can also put encrypted vars inside matrix>
118
106
119
-
You can encrypt environment variables using public key attached to your repository. The simplest way to do that is to use travis gem:
107
+
> Encrypted environment variables are not available to pull requests from forks due to the security risk of exposing such information to unknown code.
108
+
109
+
### Encrypting Variables Using a Public Key
110
+
111
+
Encrypt environment variables using the public key attached to your repository using the travis gem:
120
112
121
113
gem install travis
122
114
cd my_project
123
115
travis encrypt MY_SECRET_ENV=super_secret
124
116
125
-
Please note that secure env variables are not available for pull requests from forks. This is done due to the security risk of exposing such information in submitted code. Everyone can submit a pull request and if an unencrypted variable is available there, it could be easily displayed.
126
-
127
-
You can also automatically add it to your `.travis.yml`:
117
+
To automatically add the encrypted environment variable to your `.travis.yml`:
To make the usage of secure environment variables easier, we expose info on their availability and info about the type of this build:
132
-
133
-
*`TRAVIS_SECURE_ENV_VARS` is set to "true" or "false" depending on the availability of environment variables
134
-
*`TRAVIS_PULL_REQUEST`: The pull request number if the current job is a pull request, "false" if it's not a pull request.
135
-
136
-
Please also note that keys used for encryption and decryption are tied to the repository. If you fork a project and add it to travis, it will have different pair of keys than the original.
137
-
138
-
The encryption scheme is explained in more detail in [Encryption keys](/user/encryption-keys).
121
+
> Encryption and decryption keys are tied to the repository. If you fork a project and add it to Travis CI, it will have different keys to the original.
122
+
123
+
The encryption scheme is explained in more detail in [Encryption keys](/user/encryption-keys).
124
+
125
+
### Convenience Variables
126
+
127
+
To make using encrypted environment variables easier, the following environment variables are available:
128
+
129
+
* `TRAVIS_SECURE_ENV_VARS` "true" or "false" depending on the availability of environment variables
130
+
* `TRAVIS_PULL_REQUEST` the pull request number if the current job is a pull request, or "false" if it's not a pull request.
131
+
132
+
## Default Environment Variables
133
+
134
+
The following default environment variables are available to all builds.
135
+
136
+
* `CI=true`
137
+
* `TRAVIS=true`
138
+
* `CONTINUOUS_INTEGRATION=true`
139
+
* `DEBIAN_FRONTEND=noninteractive`
140
+
* `HAS_JOSH_K_SEAL_OF_APPROVAL=true`
141
+
* `USER=travis` (**do not depend on this value**)
142
+
* `HOME=/home/travis` (**do not depend on this value**)
0 commit comments