Echo Github Action Environment variables

Viewed 19177

I'm trying to dive in the GitHub action, and so on the .ylm files, and to understand the process I would like to echo some environment variables, such as ${{ github.repository }} or ${{ github.repository_owner }} or event secrets like ${{ secrets.GITHUB_TOKEN }} or any other, and in the output I'm getting ***.

Is there any way to force the output to show the actual values instead of the asterisks?

dev.ylm

name: Dev

on:
  workflow_dispatch:
  push:
    branches:
      - dev

env:
  BUILD_TYPE: core
  DEFAULT_PYTHON: 3.8

jobs:
  any_name:
    runs-on: ubuntu-latest
    steps:
      - name: Any Name Bash Test Step
        shell: bash
        run: |
          echo "GH_REPO: $GH_REPO"
          echo "GH_REPO_O: $GH_REPO_O"
          echo "GH_T: $GH_T"
        env:
          GH_REPO: ${{ github.repository }}
          GH_REPO_O: ${{ github.repository_owner }}
          GH_T: ${{ secrets.GITHUB_TOKEN }}

output

Run echo "GH_REPO: $GH_REPO"
  echo "GH_REPO_O: $GH_REPO_O"
  echo "GH_T: $GH_T"
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    BUILD_TYPE: core
    DEFAULT_PYTHON: 3.8
    GH_REPO: ***/core
    GH_REPO_O: ***
    GH_T: ***
GH_REPO: ***/core
GH_REPO_O: ***
GH_T: ***
2 Answers

You can't show secrets through echo otherwise there would be a huge security problem (even using env variables as an intermediary).

However, this will work with the other variables you used, the problem in your case seems to be related to the syntax. You should use run: echo "$GITHUB.REPOSITORY" and run: echo "$GITHUB.REPOSITORY_OWNER" to see them directly on your workflow.


Tip: You can identify most of the variables that can be shown with echo through the Github Context using run: echo "$GITHUB_CONTEXT" in your workflow.

Example:

Example

Picture Reference

name: This is an example

on: [pull_request]

jobs:
  one:
    runs-on: ubuntu-latest
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
      - name: Dump job context
        env:
          JOB_CONTEXT: ${{ toJson(job) }}
        run: echo "$JOB_CONTEXT"
      - name: Dump steps context
        env:
          STEPS_CONTEXT: ${{ toJson(steps) }}
        run: echo "$STEPS_CONTEXT"
      - name: Dump runner context
        env:
          RUNNER_CONTEXT: ${{ toJson(runner) }}
        run: echo "$RUNNER_CONTEXT"
      - name: Dump strategy context
        env:
          STRATEGY_CONTEXT: ${{ toJson(strategy) }}
        run: echo "$STRATEGY_CONTEXT"
      - name: Dump matrix context
        env:
          MATRIX_CONTEXT: ${{ toJson(matrix) }}
        run: echo "$MATRIX_CONTEXT"

      - name: Show default environment variables
        run: |
          echo "The job_id is: $GITHUB_JOB"   # reference the default environment variables
          echo "The id of this action is: $GITHUB_ACTION"   # reference the default environment variables
          echo "The run id is: $GITHUB_RUN_ID"
          echo "The GitHub Actor's username is: $GITHUB_ACTOR"
          echo "GitHub SHA: $GITHUB_SHA"
Related