Search code examples
githubgithub-actions

Github Actions steps id, how to call stdout of it?


So I have issue because I want to store value of my branch prefix as id but I stumbled across... how to call it in other step? I have something like this, so far I tried steps.branch-prefix.output.stdout and steps,branch-prefix.output.branch-prefix (first one was my instict because... what I do there returns all in stdout...)

Workflow sample:

name: PR Semver
on: [push]

jobs:
  update-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Get current prefix
        id: branch-prefix
        run: echo $GITHUB_REF | sed -E 's/^refs\/heads\/(.*)\/.*/\1/'
      - name: Check if branch prefix is valid (major, minor, patch)
        run: |
          echo "Checking branch prefix..."
          echo "branch prefix: ${{ steps.branch-prefix.output.stdout }}"
          if [[ ${{ steps.branch-prefix.output.stdout }} != "major" && ${{ steps.branch-prefix.output.stdout }} != "minor" && ${{ steps.branch-prefix.output.stdout }} != "patch" ]]; then
            echo "Branch prefix is not valid, exiting..."
            exit 1
          fi

Solution

  • It seems like you need to use the set-output command

    I think it would be something like

      - name: Get current prefix
        id: branch-prefix
        run: |
            prefix=$(echo $GITHUB_REF | sed -E 's/^refs\/heads\/(.*)\/.*/\1/')
            echo "::set-output name=prefix::$prefix"
    

    And getting it with ${{ steps.branch-prefix.output.prefix }}