YAML 管道中无法识别术语“System.DefaultWorkingDirectory”

时间:2021-02-09 22:19:00

标签: tfs azure-devops azure-pipelines

我有一个带有 PowerShell 任务的管道,可以运行一些 Python 脚本。它没有任何问题。 在我将我的管道转换为 YAML 格式以将其存储为代码并得到如下内容(整个 yaml 管道的一部分)之后:

    variables:
      Build.SyncSources: false
      REPO_PATH_DA: '/asdfg/qwerty'
      REPO_PATH_DS: '/zxcvbn/tyuio'
      PIP_REPO_HOST: 'bbbb.nnnn.yyyy.com'
      PIP_REPO_URL: 'https://$(PIP_REPO_HOST)/api/pypi/pypi/simple'
      PIP_VENV_NAME: 'my_test_venv'
      SelectedBranch: ''
      WorkingDirectory: $(System.DefaultWorkingDirectory)
    
…………………………………………….

    - task: PowerShell@1
      displayName: 'Install package'
      inputs:
        scriptType: inlineScript
        inlineScript: |
         .\$(PIP_VENV_NAME)\Scripts\activate
         python.exe -m pip install --index-url=$(PIP_REPO_URL) --trusted-host=$(PIP_REPO_HOST) mypackage
         python.exe -m pip install --index-url=$(PIP_REPO_URL) --trusted-host=$(PIP_REPO_HOST) $(WorkingDirectory)$(REPO_PATH_DA)\qwerty

在我运行这个管道后,我得到一个错误:

##[error]System.DefaultWorkingDirectory : The term 'System.DefaultWorkingDirectory' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

我尝试以以下格式更改变量的名称: $(env:System_DefaultWorkingDirectory) ,但没有成功。我想预定义的变量不会传递到 yaml 管道中。你有什么解决办法吗?

2 个答案:

答案 0 :(得分:1)

根据我的测试,相同的脚本可以在我的 yaml 管道中正常工作。 $(WorkingDirectory) 将转换为路径 xxx/xx/s。

检查预定义变量:$(System.DefaultWorkingDirectory) 是否已传递给 Yaml Pipeline。

您可以添加一个任务来列出所有环境变量:

steps:
- script: SET | more

在任务日志中,您可以搜索SYSTEM_DEFAULTWORKINGDIRECTORY并检查变量是否存在。

例如:

enter image description here

如果此环境变量存在,您可以尝试使用以下格式:$env:SYSTEM_DEFAULTWORKINGDIRECTORY

示例如下:

   variables:
      Build.SyncSources: false
      .....
      WorkingDirectory: '$env:SYSTEM_DEFAULTWORKINGDIRECTORY'

如果找不到这个变量,也可以检查是否有等价的变量。

例如:

BUILD_SOURCESDIRECTORY , BUILD_REPOSITORY_LOCALPATH

答案 1 :(得分:0)

这是构建还是发布管道?如果是发布版,您可能需要使用 $(Pipeline.Workspace) 而不是 $(System.DefaultWorkingDirectory)。

另外,您是否尝试过在 Powershell 任务中直接使用 $(System.WorkingDirectory),而不是声明一个引用它的变量?

相关问题