Practice Mode

GH-200

0/0 Loading...
of 0

GH-200 — 20 free practice questions

Preview the exam for free. Unlock all 106 questions →

Question 1

How should you print a debug message in your workflow?
  • A. echo "::debug::Set variable myVariable to true" Correct
  • B. echo "Set variable MyVariable to true" >> $DEBUG_MESSAGE
  • C. echo "::add-mask::Set variable myVariable to true"
  • D. echo "debug_message=Set variable myVariable to true" >> $GITHUB_OUTPUT

Explanation

Debug messages are written with the debug workflow command, ::debug::{message}, for example echo "::debug::Set variable myVariable to true". They appear in the log only when step debug logging is enabled (ACTIONS_STEP_DEBUG set to true). There is no DEBUG_MESSAGE environment file, ::add-mask:: hides a value in the logs instead of printing it, and writing to GITHUB_OUTPUT sets a step output rather than logging a message.

Question 2

As a developer, you are designing a workflow and need to communicate with the runner machine to set environment variables, output values used by other actions, add debug messages to the output logs, and other tasks. Which of the following options should you use?
  • A. composite run step
  • B. enable debug logging
  • C. self-hosted runners
  • D. environment variables
  • E. workflow commands Correct

Explanation

Workflow commands are how actions and run steps communicate with the runner machine to set environment variables, set output values used by other actions, add debug messages to the logs and perform similar tasks. Enabling debug logging only makes extra log output visible, environment variables are just values, and composite steps and self-hosted runners do not provide a channel to the runner.

Question 3

When should you use the GITHUB_TOKEN in a workflow?
  • A. when you want to make authenticated calls to the GitHub API Correct
  • B. when you want to connect to the runner via SSH
  • C. when you want to access repository-level secrets
  • D. when you want to call an action from the marketplace

Explanation

GITHUB_TOKEN is an installation access token created for each job, used to authenticate on behalf of GitHub Actions, for example when calling the GitHub API for the workflow's repository. It is not an SSH credential, secrets are read through the secrets context without it, and public Marketplace actions are referenced with uses: without any token.

Question 4

In which of the following scenarios should you use self-hosted runners? (Each correct answer presents a complete solution. Choose two.)
  • A. when the workflow jobs must be run on Windows 10
  • B. when jobs must run for longer than 6 hours Correct
  • C. when a workflow job needs to install software from the local network Correct
  • D. when GitHub Actions minutes must be used for the workflow runs
  • E. when you want to use macOS runners

Explanation

A job on a GitHub-hosted runner can run for at most 6 hours, while a job on a self-hosted runner can run for up to 5 days. A self-hosted runner also sits on your own network, so it can reach and install software from local network resources that GitHub-hosted runners cannot. Self-hosted runners do not consume GitHub Actions minutes, and macOS runners are available as GitHub-hosted runners.

Question 5

As a developer, you need to leverage Redis in your workflow. What is the best way to use Redis on a self-hosted Linux runner without affecting future workflow runs?
  • A. Install Redis on the hosted runner image and place it in a runner group. Specify label: in your job to target the runner group.
  • B. Set up Redis on a separate machine and reference that instance from your job.
  • C. Specify container: and services: in your job definition to leverage a Redis service container. Correct
  • D. Add a run step to your workflow, which dynamically installs and configures Redis as part of your job.

Explanation

A Redis service container is created fresh for the job and destroyed when the job completes, so nothing is left behind on the self-hosted runner for future runs; self-hosted runners only need to be Linux machines with Docker installed. Installing Redis on the runner image or with a run step changes the persistent runner state, and a separate shared Redis machine keeps data between runs.

Question 6

You installed specific software on a Linux self-hosted runner. You have users with workflows that need to be able to select the runner based on the identified custom software. Which steps should you perform to prepare the runner and your users to run these workflows? (Each correct answer presents part of the solution. Choose two.)
  • A. Configure the webhook and network to enable GitHub to trigger workflow.
  • B. Create the group custom-software-on-linux and move the runner into the group.
  • C. Inform users to identify the runner with the labels custom-software and linux. Correct
  • D. Add the label linux to the runner.
  • E. Inform users to identify the runner based on the group.
  • F. Add the label custom-software to the runner. Correct

Explanation

Add a custom label such as custom-software to the runner, then have users target it in runs-on with the labels custom-software and linux. The linux label is one of the default labels the runner receives automatically, so it does not need to be added. Runner groups control access rather than identifying installed software, and no webhook setup is needed because the runner polls GitHub for jobs.

Question 7

You need to trigger a workflow using the GitHub API for activity that happens outside of GitHub. Which workflow event do you use?
  • A. workflow_run
  • B. deployment
  • C. check_suite
  • D. repository_dispatch Correct

Explanation

The repository_dispatch event is triggered through the GitHub API, with a custom event_type, when you want to run a workflow for activity that happens outside of GitHub. workflow_run fires when another workflow is requested or completes, deployment fires when a deployment is created, and check_suite fires on check suite activity inside GitHub.

Question 8

In which locations can actions be referenced by workflows? (Each correct answer presents a complete solution. Choose three.)
  • A. an .action extension file in the repository
  • B. a published Docker container image on Docker Hub Correct
  • C. a public NPM registry
  • D. the runs-on: keyword of a workflow file
  • E. the repository’s Secrets settings page
  • F. a separate public repository Correct
  • G. the same repository as the workflow Correct

Explanation

A workflow can use actions from the same repository as the workflow file, from any public repository (owner/repo@ref), and from a published Docker container image on Docker Hub (docker://image:tag). Actions are not pulled from an NPM registry, there is no .action file type, runs-on selects the runner rather than an action, and the Secrets settings page stores secrets, not actions.

Question 9

Scheduled workflows run on the:
  • A. specified commit and branch from the workflow YAML file.
  • B. latest commit from the branch named schedule.
  • C. latest commit and branch on which the workflow was triggered.
  • D. latest commit from the branch named main.
  • E. latest commit on the default or base branch. Correct

Explanation

GitHub documents that scheduled workflows run on the latest commit on the default branch, and that they only run on the default branch. A schedule has no triggering branch, so the latest commit on the branch that triggered the run does not apply. The default branch need not be named main, and there is no special branch named schedule. The workflow file also cannot pin a commit for a schedule.

Question 10

Custom environment variables can be defined at multiple levels within a workflow file including: (Each answer presents a complete solution. Choose three.)
  • A. top level. Correct
  • B. step level. Correct
  • C. default level.
  • D. runner level.
  • E. job level. Correct
  • F. stage level.

Explanation

The env key can be set for the entire workflow at the top level, for a job with jobs.<job_id>.env, and for a single step with jobs.<job_id>.steps[*].env. The more specific level overrides the broader one. The defaults key sets default shell and working directory, not environment variables. Workflow syntax has no runner or stage level for env.

Question 11

You are a DevOps engineer working on deployment workflows. You need to execute the deploy job only if the current branch name is feature-branch. Which code snippet will help you to implement the conditional execution of the job?
  • A. jobs: deploy: if: github.ref_name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 Correct
  • B. jobs: deploy: if: github.branch.name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
  • C. jobs: deploy: if: github.ref.name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
  • D. jobs: deploy: if: github.branch_name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3

Explanation

github.ref_name is the short name of the branch or tag that triggered the run, for example feature-branch, so comparing it in the job-level if condition works. github.ref is a string such as refs/heads/feature-branch, so it has no name property. The github context has no branch or branch_name property, so options B and D are not valid.

Question 12

What are the mandatory requirements for publishing GitHub Actions to the GitHub Marketplace? (Each correct answer presents part of the solution. Choose two.)
  • A. The action can be either in a public or private repository.
  • B. The action’s metadata file must be in the root directory of the repository. Correct
  • C. The action’s name cannot match a user or organization on GitHub unless the user or organization owner is publishing the action. Correct
  • D. The name should match with one of the existing GitHub Marketplace categories.
  • E. Each repository can contain a collection of actions as long as they are under the same Marketplace category.

Explanation

To publish to GitHub Marketplace, the repository must contain a single action metadata file (action.yml or action.yaml) at its root. The action's name cannot match a GitHub user or organization unless that owner is publishing it. The action must be in a public repository, so A is wrong. The name must not match an existing Marketplace category, which is the opposite of D. A repository can hold only one action, so E is wrong.

Question 13

Which of the following is the proper syntax to specify a custom environment variable named MY_VARIABLE with the value my-value?
  • A. var: MY_VARIABLE = my-value
  • B. environment: MY_VARIABLE = my-value
  • C. var: MY_VARIABLE: my-value
  • D. env: MY_VARIABLE = my-value
  • E. environment: MY_VARIABLE: my-value
  • F. env: MY_VARIABLE: my-value Correct

Explanation

Custom environment variables are set with the env key as a YAML map, for example env: followed by MY_VARIABLE: my-value. The equals-sign forms are not valid YAML mappings. The environment key selects a deployment environment, not variables, and var is not a workflow key at all.

Question 14

As a DevOps engineer, you need to define a deployment workflow that runs after the build workflow has successfully completed. Without modifying the build workflow, which trigger should you define in the deployment workflow?
  • A. repository_dispatch
  • B. workflow_dispatch
  • C. workflow_exec
  • D. workflow_run Correct

Explanation

The workflow_run event lets a workflow run when another workflow is requested or completed. You can filter it on the build workflow's name and check its conclusion for success, all without changing the build workflow. repository_dispatch requires something to send an API call, which means changing the build workflow. workflow_dispatch is a manual trigger, and workflow_exec does not exist.

Question 15

Which step is using the dbserver environment variable correctly?
  • A. steps: - name: Hello world run: echo $dbserver variables: dbserver: orgserver1
  • B. steps: - name: Hello world run: echo $dbserver env: - name: dbserver value: orgserver1
  • C. steps: - name: Hello world run: echo $dbserver environment: dbserver: orgserver1
  • D. steps: - name: Hello world run: echo $dbserver env: dbserver: orgserver1 Correct

Explanation

A step defines environment variables with the env key as a map of names to values, and the run command then reads it as $dbserver. Workflow steps have no variables key. A list of name and value pairs is Kubernetes or Azure Pipelines style, not GitHub Actions syntax. environment is a job-level key for deployment environments.

Question 16

In which scenarios could the GITHUB_TOKEN be used? (Each correct answer presents a complete solution. Choose two.)
  • A. to create a repository secret
  • B. to add a member to an organization
  • C. to read from the file system on the runner
  • D. to publish to GitHub Packages Correct
  • E. to create issues in the repo Correct
  • F. to leverage a self-hosted runner

Explanation

GITHUB_TOKEN is a repository-scoped installation token. With packages: write it can publish to GitHub Packages, and with issues: write it can create issues through the API. It cannot manage secrets or organization membership, because those need a personal access token or a GitHub App. Reading the runner's file system and using a self-hosted runner need no token at all.

Question 17

As a developer, which of the following snippets will enable you to run the commands npm ci and npm run build as part of a workflow?
  • A. - run: | npm ci npm run build Correct
  • B. - shell: npm ci npm run build
  • C. - run: | npm ci npm run build shell: nodejs
  • D. - run: npm ci npm run build
  • E. - shell: | npm ci npm run build

Explanation

The run keyword executes command-line programs, and the literal block indicator (|) lets a single step run several commands, one per line, so npm ci and npm run build both run. The shell keyword only selects the shell that runs the commands, so a step with shell and no run executes nothing. nodejs is not a supported shell value (bash, pwsh, python, sh, cmd and powershell are), so the snippet that sets shell: nodejs fails. Without the |, the YAML folds the lines into a single command, npm ci npm run build, instead of running two commands.

Question 18

What is the smallest scope for an environment variable?
  • A. the workflow settings
  • B. the workflow env mapping
  • C. a job
  • D. a step Correct

Explanation

Environment variables can be set in the workflow env mapping, in a job, or in a single step (jobs.<job_id>.steps[*].env). A variable defined in a step exists only for that step and overrides job-level and workflow-level variables with the same name, which makes the step the smallest scope. A job-level variable applies to every step in the job, and the workflow env mapping applies to all jobs.

Question 19

Which workflow event is used to manually trigger a workflow run?
  • A. status
  • B. workflow_dispatch Correct
  • C. workflow_run
  • D. create

Explanation

The workflow_dispatch event lets you start a workflow manually from the Actions tab, with GitHub CLI or through the REST API, and it can define inputs. workflow_run fires automatically when another workflow is requested or completes. status fires when a commit status changes, and create fires when a branch or tag is created, so neither of them is a manual trigger.

Question 20

Where should workflow files be stored to be triggered by events in a repository?
  • A. anywhere
  • B. Nowhere; they must be attached to an action in the GitHub user interface.
  • C. .github/workflows/ Correct
  • D. .workflows/
  • E. .github/actions/

Explanation

Workflows are YAML files that must be stored in the .github/workflows directory of the repository, and GitHub only runs workflow files from that directory when their events occur. They are not attached to actions through the user interface. .workflows/ is not a recognized location, and .github/actions/ is a common place for local custom actions, not for workflows.

Verifying access...