trigger:
- master
jobs:
- job: build
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.6'
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
import os
print(os.environ.get('account_name')) # NONE
print(os.environ.get('ACCOUNT_NAME')) # NONE
print(os.environ.get('account_name_var')) # NONE
- script: echo $(ACCOUNT_NAME) # Print *** can be accessed
env:
account_name_var: $(account_name)
答案 0 :(得分:0)
尝试将环境变量放在要打印它们的脚本下。检查以下示例:
- script: |
python env.py
displayName: 'env'
env:
account_name_var: $(account_name)
答案 1 :(得分:0)
像这样更改您的PythonScript任务:
- task: PythonScript@0
displayName: 'Run a Python script'
inputs:
scriptSource: inline
script: |
import os
print(os.environ.get('ACCOUNT_NAME'))
env:
ACCOUNT_NAME: $(account_name)