Download GITHUB ACTIONS CERTIFICATION (GH-200) 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)
- 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
This structure uses nested keys to specify the event (push) and its filtering conditions (branches). Option A triggers on all pushes to all branches. Option B is invalid syntax. Option D uses incorrect YAML formatting.
- A developer wants to trigger a workflow manually from the GitHub UI. Which event should be added to the on key in the workflow file? A) push B) pull_request C) workflow_dispatch D) schedule 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.
- 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 * * *'
A) depends_on B) needs C) requires D) after CORRECT ANSWER : B) needs ✔ RATIONALE : The needs keyword is used to define dependencies between jobs. For job2 to run after job1, you would add needs: job1 to job2's configuration. This ensures job2 waits for job1 to complete (successfully) before starting.
- What is the maximum runtime for a GitHub Actions workflow job before it is automatically cancelled? A) 6 hours B) 24 hours C) 35 days D) 72 hours
CORRECT ANSWER : C) 35 days ✔ RATIONALE : GitHub Actions has a maximum job runtime of 35 days for self-hosted runners and 6 hours for GitHub-hosted runners. This limit is in place to prevent runaway workflows.
- A developer wants to share data between jobs in a workflow. Which GitHub Actions feature is designed for this purpose? A) Environment variables B) Artifacts C) Secrets D) Caching CORRECT ANSWER : B) Artifacts ✔
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.
- 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.
- 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 B) To specify the number of times a job should run C) To specify the branch on which the workflow runs D) To specify the GitHub token used for authentication CORRECT ANSWER : A) To specify the operating system and version of the runner ✔ RATIONALE : The runs-on key defines the type of runner that will execute the job. For GitHub-hosted runners, this includes operating systems like ubuntu- latest, windows-latest, or macos-latest. For self- hosted runners, it can be a custom label.
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.
- 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.
- 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' ✔
- A developer wants to create a workflow that runs on a schedule, but only on the main branch. Which configuration correctly achieves this? A) on: schedule: - cron: '0 0 * * *' branches: [main] B) on: schedule: - cron: '0 0 * * *' C) on: push: branches: [main] schedule: - cron: '0 0 * * *' D) on: schedule: - cron: '0 0 * * *' CORRECT ANSWER : C) on: push: branches: [main] schedule: - cron: '0 0 * * *' ✔ RATIONALE : To have a workflow trigger on both pushes to main and a schedule, you must list both events under the on key. The schedule event does not support branch filtering directly, so the 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.
- 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
- 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] ✔ RATIONALE : The correct YAML syntax for a matrix strategy is: yaml strategy: matrix: node-version: [16, 18, 20]
This creates three parallel jobs, each with a different node-version value.
- A workflow contains a matrix with node-version: [16, 18, 20] and os: [ubuntu-latest, windows-latest]. How many total jobs will be created? A) 3 B) 2 C) 6 D) 5 CORRECT ANSWER : C) 6 ✔ RATIONALE : A matrix strategy creates a job for every combination of the matrix variables. With 3 Node.js versions and 2 operating systems, the total number of jobs is 3 × 2 = 6.