Michael Roudnintski
Michael Roudnintski

Reputation: 382

GitHub Actions dynamic workflow name

I have a manually triggered job that builds and deploys an image based on the tag I specify. Is there a way to make the workflow name dynamic?

name: Build and push

on:
  workflow_dispatch:
    inputs:
      tag:
        description: 'Image Tag'
        required: true

jobs:
...

I would like to do something like

name: "Build and push ${{ github.event.inputs.tag }}"

Upvotes: 38

Views: 14495

Answers (4)

Koder101
Koder101

Reputation: 892

I wanted to share this workflow if anyone is looking to have a dynamic environment name in the run-name.

I can confirm that this is working for me. Although the doc says that the run-name has only access to {{ inputs }} and {{ github }} contexts, but when I added a variable at the repository level (under Github secrets) and accessed it using the vars.DEFAULT_ENVIRONMENT surprisingly it worked. You may use the same trick to achieve what you are looking for.

May be this is an undocumented feature ( bit reluctant to post if they remove it after its discovery 😁 ).

on:
  push:
    branches:
      - main
    paths:
      - 'abcd/**'
  workflow_dispatch:
    inputs:
      environment:
        description: 'Choose the deployment environment'
        required: false
        default: 'DEV'
        type: choice
        options:
          - DEV
          - UAT
          - PROD

run-name: '${{ github.event.inputs.environment || vars.DEFAULT_ENVIRONMENT }} - Run ID: ${{ github.run_id }} - by @${{ github.actor }}'

Upvotes: 1

prnvbn
prnvbn

Reputation: 1027

This can be achieved by using run-name instead of name for naming your action.

run-name: "Build and push ${{ github.event.inputs.tag }}"

Upvotes: 3

yarell
yarell

Reputation: 524

As of Sep 26th 2022, this is now supported. Here's the announcement (which contains a link to the documentataion): https://github.blog/changelog/2022-09-26-github-actions-dynamic-names-for-workflow-runs/

Upvotes: 17

fgysin
fgysin

Reputation: 11943

Workflow names are not dynamic, but fixed.

To get at the actual data of a workflow run, you'll have to chose the specific run from the Actions > All Workflows > [name-of-your-workflow] list.

Alternatively, you can think about other ways to propagate the outcomes of your builds.

  • Our team, for example, propagates build outcomes to teams chat channel (in our case Microsoft Teams using the action notify-microsoft-teams). If you search the market place you'll find plenty of actions for this.
  • Another alternative could be to generated custom badges, which you could then make visible to your team. A nice action for this is bring-your-own-badge.
  • Last but not least you can propagate your workflow run data using emails (again, there are actions which do this for you).

Upvotes: 3

Related Questions