Quick HOWTO: Run Loop in GitHub Actions

In GitHub Action workflows, there is no direct way to repeat the same job or step using variables. We have to use the "matrix" to achieve this.

Example:


my_loop_job:
name: loop job
runs-on: my-github-runners
strategy:
matrix:
my_variable: [ "var1", "var2", "var3" ]
        
steps:
- name: test loop
run: |
          echo "running the steps for $my_variable"
sh myscript.sh $



When using strategy matrix, it will create parallel jobs using the variables passed.  Maximum jobs matrix can create is 256 Jobs.


Share this

Related Posts

Previous
Next Post »

What do you think about this Article? Add your Opinion..! EmoticonEmoticon