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.
https://learn.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:
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?
Daniel's answer is correct so just to provide an example:
Create a PowerShell task to set the pipeline variable:
$fileExists = Test-Path -Path "$(System.DefaultWorkingDirectory)/file.txt"
Write-Output "##vso[task.setvariable variable=FileExists]$fileExists"
Create a secondary task that uses the variable in a custom condition:
eq(variables['FileExists'], True)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With