From dfe184f9f2c30d8b00748e58e8343ce443db95d7 Mon Sep 17 00:00:00 2001 From: Lukas Bednar Date: Tue, 30 Apr 2024 12:28:12 +0200 Subject: [PATCH] Passing URL as environment variable Signed-off-by: Lukas Bednar --- README.rst | 4 ++-- pytest_jira.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 2ffec9e..f6a0794 100644 --- a/README.rst +++ b/README.rst @@ -198,11 +198,11 @@ Usage # connection_error_strategy [strict|skip|ignore] Choose how to handle connection errors # return_jira_metadata = False (return Jira issue with metadata instead of boolean result) - You can set the password and username fields by setting the PYTEST_JIRA_PASSWORD, PYTEST_JIRA_USERNAME and - PYTEST_JIRA_TOKEN environment variables: + Alternatively, you can set the url, password, username and token fields using relevant environment variables: .. code:: sh + export PYTEST_JIRA_URL="https://..." export PYTEST_JIRA_PASSWORD="FOO" export PYTEST_JIRA_USERNAME="BAR" export PYTEST_JIRA_TOKEN="TOKEN" diff --git a/pytest_jira.py b/pytest_jira.py index 86926fe..4d458af 100644 --- a/pytest_jira.py +++ b/pytest_jira.py @@ -29,6 +29,7 @@ SKIP = 'skip' IGNORE = 'ignore' PLUGIN_NAME = "jira_plugin" +URL_ENV_VAR = 'PYTEST_JIRA_URL' PASSWORD_ENV_VAR = 'PYTEST_JIRA_PASSWORD' USERNAME_ENV_VAR = 'PYTEST_JIRA_USERNAME' TOKEN_ENV_VAR = 'PYTEST_JIRA_TOKEN' @@ -544,9 +545,11 @@ def pytest_configure(config): if not resolved_resolutions: resolved_resolutions = [] - if config.getvalue('jira') and config.getvalue('jira_url'): + if config.getvalue('jira') and ( + os.getenv(URL_ENV_VAR) or config.getvalue('jira_url') + ): jira_connection = JiraSiteConnection( - config.getvalue('jira_url'), + os.getenv(URL_ENV_VAR) or config.getvalue('jira_url'), os.getenv(USERNAME_ENV_VAR) or config.getvalue('jira_username'), os.getenv(PASSWORD_ENV_VAR) or config.getvalue('jira_password'), config.getvalue('jira_verify'),