Skip to content

Commit e475637

Browse files
authored
Merge pull request #8390 from readthedocs/env-vars-docs
Docs: environment variables
2 parents 4098944 + 5abcab5 commit e475637

8 files changed

+56
-46
lines changed

docs/api/v3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ Environment Variables are variables that you can define for your project.
12771277
These variables are used in the build process when building your documentation.
12781278
They are for example useful to define secrets in a safe way that can be used by your documentation to build properly.
12791279
Environment variables can also be made public, allowing for them to be used in PR builds.
1280-
See :doc:`/guides/environment-variables`
1280+
See :doc:`/environment-variables`.
12811281

12821282

12831283
Environment Variable details

docs/builds.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The *Sphinx* and *Mkdocs* builders set the following RTD-specific environment va
8989

9090
In case extra environment variables are needed to the build process (like secrets, tokens, etc),
9191
you can add them going to :guilabel:`Admin` > :guilabel:`Environment Variables` in your project.
92-
See :doc:`guides/environment-variables`.
92+
See :doc:`/environment-variables`.
9393

9494

9595
Docker images

docs/environment-variables.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Environment Variables
2+
=====================
3+
4+
Read the Docs provides a way to define environment variables for your project to be used in the build process.
5+
They will be exposed to all the commands executed when building your documentation.
6+
7+
For example, it may happen that your documentation depends on an authenticated service to be built properly.
8+
In this case, you will require some secrets to access these services.
9+
10+
To define an environment variable, you need to
11+
12+
#. Go to your project's :guilabel:`Admin` > :guilabel:`Environment Variables`
13+
#. Click on :guilabel:`Add Environment Variable`
14+
#. Fill the ``Name`` and ``Value`` (your secret)
15+
#. Check the :guilabel:`Public` option if you want to expose this environment variable
16+
to :doc:`builds from pull requests </pull-requests>`.
17+
18+
.. warning::
19+
20+
If you mark this option, any user that can create a pull request
21+
on your repository will be able to see the value of this environment variable.
22+
23+
#. Click on :guilabel:`Save`
24+
25+
.. note::
26+
27+
Once you create an environment variable,
28+
you won't be able to see its value anymore.
29+
30+
After adding an environment variable,
31+
you can read it from your build process,
32+
for example in your Sphinx's ``conf.py`` file:
33+
34+
.. code-block:: python
35+
36+
# conf.py
37+
import os
38+
import requests
39+
40+
# Access to our custom environment variables
41+
username = os.environ.get('USERNAME')
42+
password = os.environ.get('PASSWORD')
43+
44+
# Request a username/password protected URL
45+
response = requests.get(
46+
'https://httpbin.org/basic-auth/username/password',
47+
auth=(username, password),
48+
)

docs/guides/environment-variables.rst

Lines changed: 0 additions & 39 deletions
This file was deleted.

docs/guides/intersphinx.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Now we can add the link to the private project with the token like:
128128

129129
You can use your tokens with environment variables,
130130
so you don't have to hard code them in your ``conf.py`` file.
131-
See :doc:`/guides/environment-variables` to use environment variables inside Read the Docs.
131+
See :doc:`/environment-variables` to use environment variables inside Read the Docs.
132132

133133
For example,
134134
if you create an environment variable named ``RTD_TOKEN_DOCS`` with the token from the "docs" project.

docs/guides/platform.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ These guides will help you customize or tune aspects of Read the Docs.
1212
conda
1313
deprecating-content
1414
embedding-content
15-
environment-variables
1615
feature-flags
1716
google-analytics
1817
hiding-a-version

docs/guides/private-python-packages.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To install the package,
3434
you need to add the URI in your :ref:`requirements file <config-file/v2:Requirements file>`.
3535
Pip will automatically expand environment variables in your URI,
3636
so you don't have to hard code the token in the URI.
37-
See :doc:`using environment variables in Read the Docs </guides/environment-variables>` for more information.
37+
See :doc:`using environment variables in Read the Docs </environment-variables>` for more information.
3838

3939
.. note::
4040

@@ -108,7 +108,7 @@ If you are using a repository manager like *pypiserver*, or *Nexus Repository*,
108108
you need to set the :option:`pip:--index-url` option.
109109
You have two ways of set that option:
110110

111-
- Set the ``PIP_INDEX_URL`` :doc:`environment variable in Read the Docs </guides/environment-variables>` with the index URL.
111+
- Set the ``PIP_INDEX_URL`` :doc:`environment variable in Read the Docs </environment-variables>` with the index URL.
112112
See :ref:`pip:using environment variables`.
113113
- Put ``--index-url=https://my-index-url.com/`` at the top of your requirements file.
114114
See :ref:`pip:requirements file format`.

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ and some of the core features of Read the Docs.
8787
* **Read the Docs build process**:
8888
:doc:`Configuration reference </config-file/index>` |
8989
:doc:`Build process </builds>` |
90-
:doc:`/badges` |
90+
:doc:`/environment-variables` |
91+
:doc:`/badges`
9192

9293
* **Troubleshooting**:
9394
:doc:`/support` |
@@ -111,6 +112,7 @@ and some of the core features of Read the Docs.
111112
/connected-accounts
112113

113114
/builds
115+
/environment-variables
114116
/badges
115117

116118
/support

0 commit comments

Comments
 (0)