找不到蔚蓝管道环境

时间:2020-07-16 02:13:37

标签: python azure-devops

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)

如何将私有变量映射到环境?

找不到os.environ ACCOUNT_NAME变量

Bash可以输出ACCOUNT_NAME变量

2 个答案:

答案 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)