Docsity

GitHub Actions Certification (GH-200) Practice Questions, Exams of Software Development

Toggle sidebar
bg1
Page 1 of 94
GITHUB ACTIONS CERTIFICATION (GH-200)
QUESTIONS WITH VERIFIED ANSWERS
GRADED A+ || RECENTLY RELEASED
Devops Engineers / Software Developers /
Site Reliability Engineers
Exam coverage:-
Fundamentals of GitHub Actions: Covers core components
(events, jobs, steps, runners), trigger events (push, pull_request,
schedule, workflow_dispatch), and basic YAML syntax.
Author and Maintain Workflows: Addresses workflow structure,
job dependencies (needs), matrix strategies, concurrency control,
environment variables, and reusable workflows.
Consume and Troubleshoot Workflows: Focuses on debugging
workflows, viewing logs, using artifacts and caching, handling
errors, and troubleshooting common issues (command not found,
permission denied, timeout errors).
Author and Maintain Actions: Examines the creation of custom
actions (JavaScript, Docker, and composite actions), action.yml
metadata, inputs/outputs, and publishing actions to the GitHub
Marketplace.
Manage GitHub Actions for the Enterprise: Covers
organizational policies for actions, self-hosted runner management,
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e

Partial preview of the text

Download GitHub Actions Certification (GH-200) Practice Questions and more Exams Software Development in PDF only on Docsity!

GITHUB ACTIONS CERTIFICATION (GH-200)

QUESTIONS WITH VERIFIED ANSWERS

GRADED A+ || RECENTLY RELEASED

Devops Engineers / Software Developers /

Site Reliability Engineers

Exam coverage:-  Fundamentals of GitHub Actions : Covers core components (events, jobs, steps, runners), trigger events (push, pull_request, schedule, workflow_dispatch), and basic YAML syntax.  Author and Maintain Workflows : Addresses workflow structure, job dependencies (needs), matrix strategies, concurrency control, environment variables, and reusable workflows.  Consume and Troubleshoot Workflows : Focuses on debugging workflows, viewing logs, using artifacts and caching, handling errors, and troubleshooting common issues (command not found, permission denied, timeout errors).  Author and Maintain Actions : Examines the creation of custom actions (JavaScript, Docker, and composite actions), action.yml metadata, inputs/outputs, and publishing actions to the GitHub Marketplace.  Manage GitHub Actions for the Enterprise : Covers organizational policies for actions, self-hosted runner management,

security best practices (secrets, permissions), and auditing workflow usage. Section 1: Fundamentals of GitHub Actions (Questions 1-30)

  1. A DevOps engineer is new to GitHub Actions and needs to understand the core components that make up a workflow. Which of the following correctly identifies the primary structural components of a GitHub Actions workflow file? A) Jobs, steps, and actions B) Events, jobs, and steps C) Triggers, runners, and artifacts D) Workflows, events, and runners CORRECT ANSWER : B) Events, jobs, and steps ✔ RATIONALE : A GitHub Actions workflow is defined by three primary structural components: Events (triggers that start the workflow), Jobs (sets of steps that execute on the same runner), and Steps (individual tasks within a job that can run commands or actions). While actions (A) are a key part of steps, they are not a top-level structural component. Runners (C, D) are the execution environments, not structural elements.
  2. In a GitHub Actions workflow file, what is the correct syntax for defining a workflow that triggers on a push to the main branch? A) on: push B) on: [push]

CORRECT ANSWER : C) workflow_dispatch ✔ RATIONALE : The workflow_dispatch event allows a workflow to be triggered manually from the GitHub UI, GitHub CLI, or REST API. This is essential for manual testing or on-demand execution. push (A) is for code pushes, pull_request (B) is for pull request events, and schedule (D) is for cron-based triggers.

  1. Which of the following is a valid syntax for a schedule event trigger in a GitHub Actions workflow? A) on: schedule: - cron: '0 12 * * *' B) on: schedule: cron: '0 12 * * *' C) on: schedule: - '0 12 * * *' D) on: schedule: - cron: '0 12 * * *' CORRECT ANSWER : D) on: schedule: - cron: '0 12 * * *' ✔ RATIONALE : The correct syntax for a schedule event uses a list of cron expressions: yaml on: schedule: - cron: '0 12 * * *'

The cron key must be present. Option A is missing the cron key. Option B uses incorrect list syntax. Option C uses an invalid format for the cron expression.

  1. A workflow has multiple jobs. By default, how do these jobs execute? A) Sequentially, in the order they are defined B) In parallel, concurrently C) Sequentially, but only if they have dependencies D) In parallel, but only if they use the same runner CORRECT ANSWER : B) In parallel, concurrently ✔ RATIONALE : By default, GitHub Actions runs jobs in parallel to maximize efficiency. This means that if a workflow has multiple jobs with no dependencies specified, they will all start at the same time. Sequential execution (A) requires explicit needs dependencies. Options C and D are incorrect.
  2. An engineer needs to ensure that job2 runs only after job1 has completed successfully. Which keyword should be used in job2? A) depends_on B) needs C) requires D) after

B) Artifacts C) Secrets D) Caching CORRECT ANSWER : B) Artifacts ✔ RATIONALE : Artifacts are designed to share data between jobs in a workflow. They allow you to persist files (like build outputs, logs, or test reports) after a job completes, making them available for subsequent jobs or for download. Environment variables (A) are for configuration, secrets (C) are for sensitive data, and caching (D) is for dependencies.

  1. An engineer needs to store dependencies (like npm packages) between workflow runs to speed up execution. Which GitHub Actions feature should be used? A) Artifacts B) Environment variables C) Caching D) Secrets CORRECT ANSWER : C) Caching ✔

RATIONALE : The caching feature is specifically designed to store and reuse dependencies and other frequently used files between workflow runs. This significantly speeds up workflows by avoiding redundant downloads.

  1. A developer is writing a workflow that uses a third-party action from the GitHub Marketplace. What is the correct syntax to reference an action from the actions/checkout repository? A) uses: actions/checkout B) uses: actions/checkout@v C) uses: github/actions-checkout D) uses: actions-checkout@v CORRECT ANSWER : B) uses: actions/checkout@v4 ✔ RATIONALE : The correct syntax to reference an action is {owner}/{repo}@{ref}. For the actions/checkout action, the correct reference is actions/checkout@v4, where v4 is a version tag.
  2. What is the purpose of the runs-on key in a GitHub Actions workflow? A) To specify the operating system and version of the runner

my-runner (C) would not work because GitHub requires the self- hosted label to identify it as a self-hosted runner.

  1. In a GitHub Actions workflow, what is the default shell used for run steps on Linux runners? A) PowerShell B) Bash C) Cmd D) Python CORRECT ANSWER : B) Bash ✔ RATIONALE : On Linux and macOS runners, the default shell for run steps is Bash. On Windows runners, the default shell is PowerShell (A) or Cmd (C), depending on the context.
  2. A developer wants to run a step only when a previous step fails. Which condition expression should be used? A) if: failure() B) if: always() C) if: success() D) if: cancelled()

CORRECT ANSWER : A) if: failure() ✔ RATIONALE : The failure() function returns true when a previous step or job fails. Using if: failure() on a step ensures it only runs when a preceding step has failed.

  1. Which of the following expressions would run a step only when the workflow is triggered by a pull_request event? A) if: github.event_name == 'pull_request' B) if: github.event == 'pull_request' C) if: github.trigger == 'pull_request' D) if: github.event_type == 'pull_request' CORRECT ANSWER : A) if: github.event_name == 'pull_request' ✔ RATIONALE : The github.event_name context variable holds the name of the event that triggered the workflow. The correct expression to check for a pull_request event is if: github.event_name == 'pull_request'.
  2. An engineer needs to access the commit SHA of the push that triggered the workflow. Which context variable should be used? A) github.sha

branch must be filtered within the job using if: github.ref == 'refs/heads/main'. However, the correct way to include both triggers is to nest them properly. Option C shows a workflow that triggers on pushes to main and on a schedule.

  1. What is the purpose of the env context in GitHub Actions? A) To store secrets B) To store environment variables that are accessible to all steps in a workflow C) To store outputs from a job D) To store GitHub API tokens CORRECT ANSWER : B) To store environment variables that are accessible to all steps in a workflow ✔ RATIONALE : The env context is used to define environment variables that are available to all steps in a workflow (or job, if defined at the job level). Secrets (A) are stored separately. Outputs (C) are for passing data between steps. Tokens (D) are typically stored as secrets.
  2. A developer needs to pass a value from one step to another within the same job. Which method is most appropriate?

A) Using env variables B) Using outputs C) Using artifacts D) Using secrets CORRECT ANSWER : B) Using outputs ✔ RATIONALE : To pass a value between steps within the same job, you can use step outputs. A step can set an output using echo "value" >> $GITHUB_OUTPUT, and subsequent steps can reference it using steps..outputs.. Artifacts (C) are for sharing data between jobs, not steps.

  1. An engineer wants to use a matrix strategy to test a Node.js application on multiple versions of Node.js. Which configuration correctly defines a matrix with Node.js versions 16, 18, and 20? A) strategy: matrix: node-version: [16, 18, 20] B) strategy: matrix: node: [16, 18, 20] C) matrix: node-version: [16, 18, 20] D) strategy: matrix: {node-version: [16, 18, 20]} CORRECT ANSWER : A) strategy: matrix: node-version: [16, 18, 20] ✔
  1. A developer wants to prevent a workflow from running on forks of the repository. Which condition can be used? A) if: github.repository_owner == 'owner' B) if: github.event.repository.fork == false C) if: github.actor == 'owner' D) if: github.ref == 'refs/heads/main' CORRECT ANSWER : B) if: github.event.repository.fork == false ✔ RATIONALE : The github.event.repository.fork context variable is true if the repository is a fork. Using if: github.event.repository.fork == false ensures the workflow only runs on the original (non-fork) repository.
  2. What is the primary purpose of the GITHUB_TOKEN secret in GitHub Actions? A) To authenticate with GitHub API from within a workflow B) To store database connection strings C) To encrypt artifacts D) To configure the runner's operating system CORRECT ANSWER : A) To authenticate with GitHub API from within a workflow ✔

RATIONALE : The GITHUB_TOKEN is a automatically generated secret that GitHub provides to authenticate API requests made within a workflow. It is used for actions like checking out code, creating issues, or making commits.

  1. An engineer needs to store a sensitive API key for use in a workflow. Where should this be stored? A) As an environment variable in the workflow file B) As a secret in the repository settings C) As a step output D) As a GitHub variable CORRECT ANSWER : B) As a secret in the repository settings ✔ RATIONALE : Sensitive values like API keys, passwords, and tokens must be stored as secrets in the repository, organization, or environment settings. They are encrypted and not exposed in logs.
  2. A developer wants to run a workflow only when a pull request is opened or synchronized (e.g., new commits are pushed). Which pull request activity types should be specified?

useful for non-critical steps where failure should not halt the entire workflow.

  1. A developer wants to use a specific version of a GitHub-hosted runner, such as ubuntu-22.04. Which runs-on syntax is correct? A) runs-on: ubuntu-22. B) runs-on: ubuntu-22.04-latest C) runs-on: ubuntu@22. D) runs-on: ubuntu/22. CORRECT ANSWER : A) runs-on: ubuntu-22.04 ✔ RATIONALE : GitHub-hosted runners are specified by their image name, such as ubuntu-22.04, windows-2022, or macos-12. Using - latest (B) will use the latest version of that OS family.
  2. An engineer is setting up a workflow that uses a self-hosted runner. What must be installed on the self-hosted runner to execute GitHub Actions? A) Docker B) The GitHub Actions runner application C) Node.js D) Git LFS

CORRECT ANSWER : B) The GitHub Actions runner application ✔ RATIONALE : Self-hosted runners require the GitHub Actions runner application to be installed and configured on the machine. This application communicates with GitHub to receive and execute jobs.

  1. A developer wants to cancel a workflow run if a pull request is closed. Which event and condition can be used? A) on: pull_request: types: [closed] B) on: pull_request: types: [closed] with if: github.event.action == 'closed' C) on: pull_request: types: [closed] with if: github.event.pull_request.state == 'closed' D) on: pull_request: types: [closed] CORRECT ANSWER : B) on: pull_request: types: [closed] with if: github.event.action == 'closed' ✔ RATIONALE : While you can trigger a workflow on pull_request with types: [closed], to conditionally cancel a run, you would typically use the if condition within a job or step. However, GitHub Actions does not automatically cancel runs on PR closure; you need to