且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

任务自定义条件:给定的文件是否存在?

更新时间:2022-11-19 12:56:25

没有内置的条件或函数可以根据文件的存在或不存在进行操作.

您可以编写并运行设置变量的脚本,然后检查变量的内容.

What I'm trying to do

I have a task to execute that only makes sense if a certain config file exists. So I want to put a custom condition on the task that returns true if that file exists. I imagine a syntax like this would make sense:

condition: exists('$(projectPath)myconfigfile.xml')

This seems like a reasonable use case for custom conditions.

What Microsoft documents

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#functions

Microsoft says the following functions are always available: and, coalesce, contains, endsWith, eq, format, ge, gt, in, le, lt, ne, not, notIn, or, startsWith, xor. And furthermore:

My actual question

I'm finding this a little frustrating. What "other functions" are there? How can I research them? And in particular, is there one that takes a filename and tells me if that file exists?

There is no built in condition or function that operates off of the presence or absence of a file.

You can write and run a script that sets a variable, then check the contents of the variable.