How to run same github actions job multiple times?

Viewed 18

I'm using gradle. I have project like that:

project/
--- sub1/
--- sub2/

I want to have artifact uploaded as 2 differents files (i.e. sub1.jar and sub2.jar separately).

Actually, I'm using this job:

- uses: actions/upload-artifact@v3
  with:
    name: Artifacts
    path: project*/build/libs/*.jar

But the file uploaded is only one file, with sub folder to files.

I tried to run same upload-artifact job, but with different argument. I can't do that.

I don't want to copy/paste the same job, because in the futur I will have multiple sub project, and I don't want to have 50 lines or same code ...

How can I upload my generated files, or run same job multiple times ?

1 Answers

So using a matrix strategy would allow you to do this for a list of inputs.

You can do something like this as job in a workflow which would do the same steps for each value in the matrix.

  some-job:
    name: Job 1
    runs-on: ubuntu-latest
    strategy:
      matrix:
        subdir: [sub1, sub2]
    steps:
      - name: Create some files
        run: echo "test data" > /tmp/${{ matrix.subdir }}/.test.jar

      - uses: actions/upload-artifact@v3
        with:
          name: Artifacts
          path: /tmp/${{ matrix.subdir }}/*.jar
Related