How to avoid duplication of file lists in Azure DevOps / GitHub pipelines?
Suppose I have the following YAML file:
name: Build
on:
push:
branches: [ master ]
paths:
- 'SRC/define.inc'
- 'SRC/SrvMain.pas'
- 'SRC/Tiny.dpr'
- 'SRC/xBase.pas'
pull_request:
branches: [ master ]
paths:
- 'SRC/define.inc'
- 'SRC/SrvMain.pas'
- 'SRC/Tiny.dpr'
- 'SRC/xBase.pas'
workflow_dispatch:
jobs:
...skipped remaining lines...
(I'm using this pipeline for the TinyWeb repository on GitHub)
As you see, the list of files under the paths:
section repeats for the "push" and "pull_request" sections. How can I define a list of files just once, so I would not need to copy it to each of the sections, but only add a reference to the list variable? I've tried to define the list using the variables:
keyword and then reference the list as ${{ variables.my_variable_name }}
, but it didn't work. I tried multiple variants to no avail.
Please give an example of the YAML file where I can define the list of files once and then use it from multiple sections under on:
.
Hi @Maxim Masiutin I have tried with both env
and secrets
but it didn't work out. You are asking for using one path for both push
and pull_request
events and it is not possible for now. There is no statements that shows supporting for variables at workflow level. You can check this for paths/paths_ignore.
However you are using both push
and pull_request
events exactly same I think you may use like below:
name: Build
on:
push:
pull_request:
branches: [ master ]
paths:
- 'SRC/define.inc'
- 'SRC/SrvMain.pas'
- 'SRC/Tiny.dpr'
- 'SRC/xBase.pas'
workflow_dispatch:
jobs:
I hope this works for you.
This syntax worked for me on Azure.
name: Build
variables:
src_define: 'SRC/define.inc'
src_srvmain: 'SRC/SrvMain.pas'
src_tiny: 'SRC/Tiny.dpr'
src_xbase: 'SRC/xBase.pas'
on:
push:
branches: [ master ]
paths:
- variables['src_define']
- variables['src_srvmain']
- variables['src_tiny']
- variables['src_xbase']
pull_request:
branches: [ master ]
paths:
- variables['src_define']
- variables['src_srvmain']
- variables['src_tiny']
- variables['src_xbase']
workflow_dispatch:
jobs:
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