You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Strategy matrix and secret dereference](#strategy-matrix-and-secret-dereference)
56
-
-[Strategy matrix and environment variables](#strategy-matrix-and-environment-variables)
55
+
-[Matrix](#matrix)
57
56
-[Timeout settings](#timeout-settings)
58
57
-[Workflow dispatch and passing input](#workflow-dispatch-and-passing-input)
59
58
-[Workflow dispatch with mixed input type](#workflow-dispatch-with-mixed-input-type)
@@ -1782,11 +1781,68 @@ jobs:
1782
1781
1783
1782
```
1784
1783
1785
-
## Strategy matrix and secret dereference
1784
+
## Matrix
1786
1785
1787
-
matrix cannot reference `secret` context, so pass secret key in matrix then dereference secret with `secrets[matrix.SECRET_KEY]`.
1786
+
Matrix is useful when you want to run same job with different parameters like OS, version and so on. Matrix can define with `jobs.<job_id>.strategy.matrix`. Following example shows how to use matrix.
1788
1787
1789
-
let's set secrets in settings.
1788
+
- To control how job failures are handled, use `fail-fast: false` to continue other matrix jobs when one of matrix job fails.
1789
+
- Matrix runs jobs in parallel by default. However you can set parallelism with `max-parallel` to limit number of parallel jobs.
1790
+
- Matrix can define multiple axis like OS and version. Following example will run 6 jobs in parallel (3 versions x 2 OS).
1791
+
1792
+
```yaml
1793
+
# .github/workflows/matrix.yaml
1794
+
1795
+
name: matrix
1796
+
on:
1797
+
workflow_dispatch:
1798
+
push:
1799
+
branches: ["main"]
1800
+
pull_request:
1801
+
branches: ["main"]
1802
+
1803
+
jobs:
1804
+
parallel:
1805
+
strategy:
1806
+
# If set true, then if one matrix job fails, cancel others
1807
+
fail-fast: false # default is true.
1808
+
matrix:
1809
+
version: [10, 12, 14]
1810
+
runs-on: [ubuntu-24.04, ubuntu-latest]
1811
+
permissions:
1812
+
contents: read
1813
+
runs-on: ${{ matrix.runs-on }}
1814
+
timeout-minutes: 3
1815
+
steps:
1816
+
- name: Show runner info
1817
+
run: |
1818
+
echo "runner.os: ${{ runner.os }}"
1819
+
echo "matrix.runs-on: ${{ matrix.runs-on }}"
1820
+
echo "matrix.version: ${{ matrix.version }}"
1821
+
1822
+
serial:
1823
+
strategy:
1824
+
# run matrix jobs one by one = serial execution
1825
+
max-parallel: 1
1826
+
matrix:
1827
+
version: [10, 12, 14]
1828
+
runs-on: [ubuntu-24.04, ubuntu-latest]
1829
+
permissions:
1830
+
contents: read
1831
+
runs-on: ${{ matrix.runs-on }}
1832
+
timeout-minutes: 3
1833
+
steps:
1834
+
- name: Show runner info
1835
+
run: |
1836
+
echo "runner.os: ${{ runner.os }}"
1837
+
echo "matrix.runs-on: ${{ matrix.runs-on }}"
1838
+
1839
+
```
1840
+
1841
+
**Secret dereference in matrix**
1842
+
1843
+
You cannot reference `secret` context inside `strategy.matrix` section, so pass secret key in matrix then dereference secret with `secrets[matrix.SECRET_KEY]`.
1844
+
1845
+
Let's set secrets in settings, then run following workflow.
# you can not use expression inside env:. do it on step.
1864
1917
steps:
1865
1918
- run: echo "${ORG}"
1866
1919
- run: echo "${NEW_ORG}"
@@ -1869,6 +1922,42 @@ jobs:
1869
1922
1870
1923
```
1871
1924
1925
+
**Matrix includes/excludes**
1926
+
1927
+
Ise `include` to expand existing matrix, and use `exclude` to remove matrix combinations. Both are optional, and you can directly specify `include` without specifying base matrix.
1928
+
1929
+
Following example shows `include` to define 3 matrix items, then `exclude` to remove one item from matrix. Result is 2 matrix jobs `apples` and `carrots`.
1930
+
1931
+
```yaml
1932
+
# .github/workflows/matrix-include-exclude.yaml
1933
+
1934
+
name: matrix include exclude
1935
+
on:
1936
+
workflow_dispatch:
1937
+
push:
1938
+
branches: ["main"]
1939
+
pull_request:
1940
+
branches: ["main"]
1941
+
1942
+
jobs:
1943
+
echo:
1944
+
strategy:
1945
+
matrix:
1946
+
include:
1947
+
- fruit: apples
1948
+
- fruit: bananas
1949
+
- fruit: carrots
1950
+
exclude:
1951
+
- fruit: bananas
1952
+
permissions:
1953
+
contents: read
1954
+
runs-on: ubuntu-24.04
1955
+
timeout-minutes: 3
1956
+
steps:
1957
+
- run: echo "${matrix.fruit}"
1958
+
1959
+
```
1960
+
1872
1961
## Timeout settings
1873
1962
1874
1963
You can set timeout for both `job` and `steps`.
@@ -3169,6 +3258,39 @@ Service container is used to run container alongside your job. Typical usecase i
0 commit comments