Dynamic naming for build artifacts zip file

1.6k Views Asked by At

in my repo, I have yml file with the code below /.github/workflows/filename.yml

 -  name: Create Artifact
     uses: actions/upload-artifiact@v2
     with:
       name: Report.22.9.zip
       path: |
         project
         !project/Reports/*
         !project/Logs/*
         !project/Snapshots/*

Now, I'm trying to make "name: Report.22.9.zip" more dynamic. Something like this

<repo_name>.<branch_name>.<git_build_id>.zip
1

There are 1 best solutions below

1
frennky On

You can create artifact name in previous step and provide it as output to be used by artifact upload step.

name: Dynamic artifact name

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Generate artifact name
        id: generate-name
        run: |
          echo "::set-output name=artifact::${{ github.event.repository.name }}.${{ github.ref_name }}.${{ github.run_id }}.zip"

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: ${{ steps.generate-name.outputs.artifact }}
          path: ./README.md