Skip to content

Commit 3114f95

Browse files
committed
Build: expose VCS-related environment variables
Introduce 3 new variables: * `READTHEDOCS_REPOSITORY_URL` * `READTHEDOCS_REPOSITORY_IDENTIFIER` * `READTHEDOCS_REPOSITORY_IDENTIFIER_HASH` Closes #9423
1 parent 4687f09 commit 3114f95

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docs/user/reference/environment-variables.rst

+25
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ All :doc:`build processes </builds>` have the following environment variables au
5656
:Example: ``https://docs.readthedocs.io/ja/stable/``
5757
:Example: ``https://example--17.org.readthedocs.build/fr/17/``
5858

59+
.. envvar:: READTHEDOCS_REPOSITORY_URL
60+
61+
URL from where the source code to generate the documentation is clonned.
62+
It could be HTTPS, SSH or any other URL scheme supported by Git.
63+
This is the same URL defined under :guilabel:`Admin` > :guilabel:`Settings` > :guilabel:`Repository URL`.
64+
65+
:Example: ``https://github.com/readthedocs/readthedocs.org``
66+
:Example: ``[email protected]:readthedocs/readthedocs.org.git``
67+
68+
.. envvar:: READTHEDOCS_REPOSITORY_IDENTIFIER
69+
70+
Git identifier checked out from the repository URL.
71+
It could be a branch or tag name.
72+
73+
:Example: ``v1.x``
74+
:Example: ``bugfix/docs-typo``
75+
:Example: ``feature/signup``
76+
:Example: ``update-readme``
77+
78+
.. envvar:: READTHEDOCS_REPOSITORY_IDENTIFIER_HASH
79+
80+
Git commit hash identifier checked out from the repository URL.
81+
82+
:Example: ``1f94e04b7f596c309b7efab4e7630ed78e85a1f1``
83+
5984
.. seealso::
6085

6186
:doc:`/environment-variables`

readthedocs/doc_builder/director.py

+3
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ def get_rtd_env_vars(self):
574574
"READTHEDOCS_OUTPUT": os.path.join(
575575
self.data.project.checkout_path(self.data.version.slug), "_readthedocs/"
576576
),
577+
"READTHEDOCS_REPOSITORY_URL": self.data.project.repo,
578+
"READTHEDOCS_REPOSITORY_IDENTIFIER": self.data.version.identifier,
579+
"READTHEDOCS_REPOSITORY_IDENTIFIER_HASH": self.data.build["commit"],
577580
}
578581
return env
579582

readthedocs/projects/tests/test_build_tasks.py

+3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ def test_get_env_vars(self, load_yaml_config, build_environment, config, externa
279279
"READTHEDOCS_OUTPUT": os.path.join(
280280
self.project.checkout_path(self.version.slug), "_readthedocs/"
281281
),
282+
"READTHEDOCS_REPOSITORY_URL": self.project.repo,
283+
"READTHEDOCS_REPOSITORY_IDENTIFIER": self.version.identifier,
284+
"READTHEDOCS_REPOSITORY_IDENTIFIER_HASH": self.build.commit,
282285
}
283286

284287
self._trigger_update_docs_task()

0 commit comments

Comments
 (0)