George Shuklin
George Shuklin

Reputation: 7917

How to get a name of the user, resposible for triggering workflow in github actions

We have notifications on deployments, which are send to the corporate chat. When user run code locally, there is some amount of information to identify 'who run the code' ($USER, $HOSTNAME, etc).

When the same code is triggered from CI, I would like to have information on 'who is the cause' for this workflow. It may be a github account name for the user to click on `workflow_dispatch', or author for commit in git, or author or PR, etc.

Is there such info available to workflows in Github Actions?

Upvotes: 8

Views: 13944

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 23270

You might be interested by the Github Context concept.

There, you'll see that on each workflow, you can access context variables, such as the github.actor variable to access the login of the user that initiated the workflow run.

TIP: You can print the workflow GitHub variables using the following step:

- name: Show GitHub context   
  env: 
    GITHUB_CONTEXT: ${{ toJson(github) }}   
  run: echo "$GITHUB_CONTEXT"
  shell: bash

Otherwise, here is a payload sample to know what are the available variables.

Upvotes: 15

Related Questions