首页 > 解决方案 > 条件内带有 bash 表达式的 Azure Pipeline

问题描述

如何在条件下使用 bash 脚本?

- bash: export PYTHONPATH="src/"
  condition: succeeded(fileExists('./src/'))
  displayName: Add src/ Path if Exists

condition: succeeded(fileExists('./src/'))这似乎不起作用,它在下面显示以下错误消息:

##[error]Unrecognized value: 'fileExists'.

标签: azure-devopsyamlazure-pipelines

解决方案


条件不是这样,您可以在那里检查变量值,检查文档

因此,如果要检查文件是否存在,则需要添加另一个脚本任务来检查文件是否存在,如果存在则设置一个变量,而不是在条件中使用此变量。

像这样的东西:

- bash: |
   if [ -f /tmp/foo.txt ]; then
       echo "##vso[task.setvariable variable=fileExist]true"
   fi

- bash: export PYTHONPATH="src/"
  condition: and(succeeded(), eq(variables['fileExist'], 'true'))

推荐阅读