[英]Azure pipeline environment variables failing
我有以下 yaml 管道构建文件:
pr:
branches:
include:
- master
jobs:
- job: 'Test'
pool:
vmImage: 'Ubuntu-16.04'
strategy:
matrix:
Python36:
python.version: '3.6'
maxParallel: 4
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
architecture: 'x64'
env:
POSTGRES: $(POSTGRES)
- script: python -m pip install --upgrade pip && pip install -r requirements.txt
displayName: 'Install dependencies'
- script: |
pip install pytest
pytest tests -s --doctest-modules --junitxml=junit/test-results.xml
displayName: 'pytest'
我将管道设置中的变量POSTGRES
设置为秘密变量。 在 python 代码中,所有环境变量都是通过调用读取的
if not os.getenv(var):
raise ValueError(f'Environment variable \'{var}\' is not set')
执行构建时,它会准确地为POSTGRES
变量抛出上述错误。 环境变量设置不正确?
要使环境变量在 Python 脚本中可用,您需要在使用它的步骤中定义它:
- script: |
pip install pytest
pytest tests -s --doctest-modules --junitxml=junit/test-results.xml
displayName: 'pytest'
env:
POSTGRES: $(POSTGRES)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.