CI/CD and Git practice questions
Fifteen free CI/CD and Git practice questions with explained answers, written for anyone preparing for a Microsoft DevOps exam. Continuous integration and continuous delivery (CI/CD) automate building, testing and releasing code from a Git repository, and the exam asks which control, command or strategy fits a described situation. The topic is tested in the source control and build and release domains of AZ-400. All questions are original and use Azure DevOps and GitHub terminology.
How to use these questions
Answer each question before opening the explanation, and commit to one letter. Underline the constraint word in the stem, such as “without rewriting history”, “no long-lived secret” or “only on main”, because it usually separates two similar options. Read the explanation even when the answer was right, since each one also says why the other three options fail. The concepts behind the questions are covered in the CI/CD explained topic guide.
Warm-up: terms and basic controls
Question 1. Every commit that passes the automated build and tests produces a release that is ready for production, but a release manager must click to approve each production release. Which practice is this?
- A. Continuous integration
- B. Continuous deployment
- C. Continuous monitoring
- D. Continuous delivery
Show answer
Answer: D
Continuous delivery keeps every passing change in a deployable state and leaves the final production release as a manual decision. Continuous deployment would release automatically with no click. Continuous integration only covers merging and building or testing changes frequently. Continuous monitoring observes running systems and is not a release practice.
Question 2. A team adds a workflow file named build.yml to the root of its GitHub repository, and no run ever appears in the Actions tab. Where must the file be stored for GitHub Actions to find it?
- A. The root of the repository, with any file name
- B. The .github/workflows directory
- C. The .github/actions directory
- D. A folder named azure-pipelines
Show answer
Answer: B
GitHub Actions only reads workflow files from the .github/workflows directory of the repository. The repository root is not scanned. The .github/actions directory is a conventional place for local composite actions, not for workflows. A folder named for Azure Pipelines is irrelevant to GitHub.
Question 3. A commit with a bug was pushed to main and other developers have already pulled it. The change must be undone without rewriting shared history. Which command is appropriate?
- A. git revert on the bad commit
- B. git reset –hard HEAD~1 followed by a force push
- C. An interactive rebase that drops the commit, then a force push
- D. git stash
Show answer
Answer: A
git revert creates a new commit that applies the inverse of the bad commit, so history only moves forward and no one’s clone breaks. git reset –hard followed by a force push rewrites shared history and breaks other clones. Dropping the commit in an interactive rebase also rewrites history. git stash only shelves uncommitted local changes.
Question 4. Pull requests into main must always land as exactly one commit, so the history reads as one entry per change and the many work-in-progress commits of the branch disappear. Which merge type should be allowed?
- A. Merge (no fast-forward)
- B. Rebase and fast-forward
- C. Squash merge
- D. Cherry-pick
Show answer
Answer: C
Squash merge combines all commits of the pull request into a single new commit on the target branch. A merge commit keeps every branch commit and adds a merge commit. Rebase and fast-forward keeps a linear history but still adds each individual commit. Cherry-pick copies selected commits and is not a pull request merge type.
Question 5. In Azure Repos, nobody should be able to complete a pull request into main unless the code builds successfully with the change included. Which branch policy enforces this?
- A. Require linked work items
- B. A CI trigger on the main branch
- C. A build validation policy
- D. Limit merge types to squash
Show answer
Answer: C
A build validation policy queues the configured pipeline for each pull request and blocks completion until it succeeds. Requiring linked work items enforces traceability, not a passing build. A CI trigger on main runs after the merge, which is too late. Limiting merge types to squash controls history shape, not quality.
Scenarios: pipelines and releases
Question 6. A GitHub Actions workflow deploys to Azure. The security team requires that no long-lived secret or password is stored in GitHub. What should be configured?
- A. Workload identity federation (OIDC) with azure/login and the id-token: write permission
- B. A client secret stored in a plain repository variable
- C. A service principal password stored as an encrypted secret and rotated yearly
- D. A publish profile committed to the repository
Show answer
Answer: A
OpenID Connect lets the workflow request a short-lived token: create a federated credential on a Microsoft Entra app registration trusting the repository, grant the job the id-token: write permission and use azure/login with the client, tenant and subscription IDs. A client secret stored in a repository variable or as an encrypted secret is still a long-lived credential. A publish profile file is also a stored credential.
Question 7. Deployment to the production stage of an Azure Pipelines YAML pipeline must wait until the release managers approve it, even though the build and test stages passed. What should be used?
- A. A branch policy requiring two reviewers
- B. A pipeline variable marked as secret
- C. A scheduled trigger at night
- D. An environment with an approval check
Show answer
Answer: D
An environment with an approval check pauses any deployment job that targets the environment until the named approvers respond. A branch policy requiring reviewers gates code in pull requests, not deployments. Marking a variable as secret only hides its value. A scheduled trigger starts runs at a time and does not ask anyone to approve.
Question 8. A pipeline builds the application again in each of the dev, test and production stages. Production once behaved differently from what was tested. Which change fixes the process?
- A. Rebuild from the same commit in each stage with the latest packages
- B. Publish one build artifact and deploy it to every stage
- C. Skip tests in the dev stage to save time
- D. Build on a developer machine and upload the result
Show answer
Answer: B
Build once, deploy many: publish the build output as an artifact and deploy that same immutable artifact to every stage, so what was tested is what is released. Rebuilding per stage can produce different binaries from changed dependencies or tooling. Skipping tests makes things worse. Building on a developer machine removes repeatability.
Question 9. Design teams commit 200 MB PSD files that change often. The repository has become huge and clones are slow, but the files must stay versioned with the code. What should be used?
- A. Add the files to .gitignore
- B. Tell everyone to clone with –depth 1
- C. Track the files with Git LFS
- D. Zip the files before committing them
Show answer
Answer: C
Git LFS stores small pointer files in the repository and keeps the large content on an LFS server, so history and clones stay small while the files remain versioned. Adding them to .gitignore stops versioning them. A shallow clone only limits how much history one person downloads and does not change how the files are stored. Compressing the files into a zip still stores each large version in history.
Question 10. A team wants to send 5 percent of production traffic to the new version, watch error rates, and only then increase the share. Which deployment strategy is this?
- A. Canary
- B. Blue-green
- C. Rolling
- D. Big bang
Show answer
Answer: A
A canary release exposes the new version to a small, controlled share of traffic first and expands it as metrics stay healthy. Blue-green switches all traffic from one full environment to the other at once. A rolling deployment replaces instances in batches and does not let you set a traffic percentage. A big-bang release replaces everything at once with no gradual exposure.
Edge cases and traps
Question 11. A developer pushed an access key to a shared repository, and it is visible in several old commits. What is the correct response?
- A. Delete the file in a new commit
- B. Revoke and rotate the key, then purge it from history
- C. Only rewrite history to remove the key
- D. Make the repository private
Show answer
Answer: B
The key must be treated as compromised, so revoke and rotate it first, then remove it from history with a tool such as git filter-repo or BFG and have everyone re-clone. Deleting the file in a new commit leaves the key in history. Rewriting history without revoking leaves a key that may already have been copied. Making the repository private does not undo earlier exposure.
Question 12. A developer ran git reset --hard HEAD~3 on a local branch and lost three commits that were never pushed. Which approach recovers them?
- A. Run git log to find the commits on the branch
- B. Run git stash pop
- C. Run git revert HEAD
- D. Run git reflog, then reset or branch at the lost commit hash
Show answer
Answer: D
The reflog records where HEAD and branches pointed, so git reflog shows the lost commit hashes and git reset –hard to the right entry (or a new branch at that hash) brings them back. git log follows the current branch and no longer lists the commits. git stash pop restores stashed changes, which these are not. git revert HEAD adds a commit that undoes the latest commit and recovers nothing.
Question 13. An Azure App Service web app must be tested in a production-like setup and then released with no downtime, with an immediate way back if the release misbehaves. What fits best?
- A. Deploy directly to the production slot
- B. Deploy to a staging slot, test it, then swap slots
- C. Stop the app, deploy and start it again
- D. Create a second plan and change DNS by hand
Show answer
Answer: B
Deploy to a staging deployment slot, warm and test it, then swap it with production; if problems appear, swap back. Deploying straight to the production slot gives no test stage and causes restarts. Stopping the app during deployment causes downtime. A second App Service plan with a manual DNS change is slower, riskier to roll back and unnecessary when slots exist.
Question 14. A team practicing trunk-based development merges to main daily, but a new checkout feature takes three weeks to finish and must not be visible to users until it is ready. What is the best approach?
- A. Merge to main daily with the feature behind a flag that is switched off
- B. Keep a feature branch open for three weeks and merge once at the end
- C. Hold the work on a laptop until the feature is complete
- D. Deploy it and ask users not to use the new page
Show answer
Answer: A
Merge the unfinished code to main behind a feature flag that is off, so integration stays continuous and release is decoupled from deployment. A long-lived feature branch delays integration and invites painful merges. Holding back merges until the end gives the same problem. Deploying to production and hoping users do not notice is not a control.
Question 15. In an Azure Pipelines YAML pipeline, the Deploy stage must run only when the previous stages succeeded and the source branch is main. Which condition on the stage achieves this?
- A.
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main') - B.
condition: eq(variables['Build.SourceBranch'], 'main') - C.
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) - D.
condition: always()
Show answer
Answer: C
A custom condition replaces the default succeeded() check, so it must include it: and(succeeded(), eq(variables[‘Build.SourceBranch’], ‘refs/heads/main’)). The branch test alone would also run after failed stages. always() runs regardless of outcome and branch. Build.SourceBranch holds the full ref, so comparing it to the short name main never matches.
Where to go next
Read the CI/CD explained topic guide for pipelines, branching, approvals and deployment strategies. Related practice sets are infrastructure as code practice questions and Delta Lake and Spark practice questions. For timed mixed practice, take the free 20-question AZ-400 practice test, and read the multiple-choice exam tips.