我想在我的 python 代码中从 jenkins 获取所需功能的变量值

I want to get variable values from jenkins in my python code for desired capabilities

我想将所需的功能从 jenkins 传递给 sauce lab

我已经在 python

中编写了我的代码
desired_caps = {}
desired_caps['platform'] = os.getenv('platform','SELENIUM_PLATFORM')
desired_caps['browserName'] = os.getenv('browserName','SELENIUM_BROWSER')
desired_caps['version'] = os.getenv('version','SELENIUM_VERSION')
context.browser = webdriver.Remote(
    command_executor='http://USER_NAME:KEY@ondemand.saucelabs.com:80/wd/hub',
    desired_capabilities=desired_caps)

运行 构建时在 jenkins 上出现此错误:

Starting pre-build for Sauce Labs plugin
Finished pre-build for Sauce Labs plugin
$ cmd /c call C:\WINDOWS\TEMP\jenkins6037287030698812464.bat
selenium.common.exceptions.WebDriverException: Message: Misconfigured -- 
Unsupported OS/browser/version/device combo: OS: 'SELENIUM_PLATFORM', 
Browser: 'selenium_browser', Version: 'SELENIUM_VERSION.', Device: 
'unspecified'

Executing before all - creating benemax admin with owner permission to use it 
everywhere
User data: {}
Exception WebDriverException: Message: Misconfigured -- Unsupported 
OS/browser/version/device combo: OS: 'SELENIUM_PLATFORM', Browser: 
'selenium_browser', Version: 'SELENIUM_VERSION.', Device: 'unspecified'

C:\Program Files (x86)\Jenkins\workspace\project>exit 1 
Build step 'Execute Windows batch command' marked build as failure
Starting post-build for Sauce Labs plugin
Updating the custom data field for jobs with Jenkins build info for analytics
Stopped/completed/updated 0 jobs
Finished post-build for Sauce Labs plugin
Starting Sauce Labs test publisher
The Sauce OnDemand plugin is configured, but no session IDs were found in the 
test output.
Finished Sauce Labs test publisher
Finished: FAILURE

您似乎使用 os.getEnv 错误。

os.getenv('version','SELENIUM_VERSION') 应该很可能只是 os.getenv('SELENIUM_VERSION')

函数的第二个参数是默认值,第一个是你要获取的环境变量。 https://docs.python.org/3.7/library/os.html#os.getenv

现在发生的事情是您尝试获取名为 version 的环境变量的值,该变量不存在,然后它默认返回文字字符串 'SELENIUM_VERSION'.