Skip to content

Latest commit

 

History

History
62 lines (51 loc) · 2.31 KB

02.B-Create-Context-Job.md

File metadata and controls

62 lines (51 loc) · 2.31 KB

GitHub Context

GitHub Actions store information about the job, environment, and other aspects of the jobs contexts.

See the documentation for context details.

Once the job runs, you will be able to see all variables of the job, and what could be available to you. This is helpful to debug environments and see what variables are available to you. You could then copy this code into another running workflow and see the output that is generated by that job.

  1. Create a branch called context-job

  2. Create a file, .github/workflows/context.yml

  3. Copy the following code:

    ⚠️ Note: This job is primarily used for debugging, or helping the user to find variable information stored in a running job.

    # This is a basic workflow to help you get started with Actions
    
    name: Context Info
    
    # Controls when the action will run.
    on:
      # Triggers the workflow on push or pull request events but only for the master branch
      push:
        branches-ignore: main
    
    # A workflow run is made up of one or more jobs that can run sequentially or in parallel
    jobs:
      Context-Info:
        # The type of runner that the job will run on
        runs-on: ubuntu-latest
    
        # Steps represent a sequence of tasks that will be executed as part of the job
        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"
  4. Open a pull request and merge the context-job branch into the main branch.