Do you need to check if the templates files are exist or compare some codes in yaml files
In your current situation, we recommend you can try to make your templates as the template yaml file, and then we can use the resources, stages and pipeline conditions
Here is the example demo script:
resources:
repositories:
- repository: templates
type: git
name: Tech-Talk/template
trigger:
paths:
include:
- "temp.yaml"
trigger: none
# variables:
# - name: Test
# value: TestGroup
pool:
vmImage: ubuntu-latest
stages:
- stage: A
jobs:
- job: A1
steps:
- checkout: templates
- bash: ls $(System.DefaultWorkingDirectory)
- bash: |
if [ -f temp.yaml ]; then
# this is used to check if the file is exist: if [ -f your-file-here ]
echo "##vso[task.setVariable variable=FILEEXISTS;isOutput=true]true"
else
echo "##vso[task.setVariable variable=FILEEXISTS;isOutput=true]false"
fi
# or on Windows:
# - script: echo ##vso[task.setvariable variable=FILEEXISTS;isOutput=true]true
name: printvar
- stage: B
condition: eq(dependencies.A.outputs['A1.printvar.FILEEXISTS'], 'true')
dependsOn: A
jobs:
- job: B1
steps:
- script: echo hello from Stage B
# - template: temp.yaml@templates
# parameters:
# agent_pool_name: ''
# db_resource_path: $(System.DefaultWorkingDirectory)
# variable_group: ${{variables.Test}}
Update:
And if you need to use the Windows agent, please refer this task:
- task: PowerShell@2
name: printvar
inputs:
targetType: 'inline'
script: |
$file = '$(System.DefaultWorkingDirectory)\temp.yaml'
if([System.IO.File]::Exists($file)){
Write-Host "##vso[task.setvariable variable=FILEEXISTS;isOutput=true]true"
}
else{
Write-Host "##vso[task.setvariable variable=FILEEXISTS;isOutput=true]false"
}
Attach my test result:
