Download GITHUB ACTIONS CERTIFICATION (GH-200) 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)
- 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.
- 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] C) on: push: branches: [main] D) on: push: { branches: main } CORRECT ANSWER : C) on: push: branches: [main]
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 * * *'
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.
- 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.
- 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
- 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 : 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.
- 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.
- 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@v
A) runs-on: self-hosted B) runs-on: [self-hosted, my-runner] C) runs-on: my-runner D) runs-on: [my-runner] CORRECT ANSWER : B) runs-on: [self-hosted, my-runner] RATIONALE : To target a specific self-hosted runner, you must include the self-hosted label along with the runner's custom label. The syntax is runs-on: [self-hosted, my-runner]. Using only my-runner (C) would not work because GitHub requires the self-hosted label to identify it as a self-hosted runner.
- 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.
- 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'
- 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 data between steps. Tokens (D) are typically stored as secrets.
- 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
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.
- 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.
- 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
A) types: [opened, synchronize] B) types: [opened, edited] C) types: [opened, reopened] D) types: [opened, closed] CORRECT ANSWER : A) types: [opened, synchronize] RATIONALE : The pull_request event allows filtering by activity types. opened triggers when a PR is created, and synchronize triggers when new commits are pushed to the PR branch. This is a common configuration for CI workflows.
- What is the function of the continue-on-error keyword in a GitHub Actions step? A) It prevents the step from running if an error occurs B) It allows the step to fail without failing the entire job C) It retries the step if it fails D) It logs the error but continues the workflow CORRECT ANSWER : B) It allows the step to fail without failing the entire job
RATIONALE : Setting continue-on-error: true on a step allows it to fail, but the job will continue to run subsequent steps. This is useful for non-critical steps where failure should not halt the entire workflow.
- 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. 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.
- 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