300-910 · Question #72
A DevOps engineer is designing a precheck validation of the network state in a CI/CD pipeline and must implement this workflow: - Take a source Docker image named alpine - Define two stages named buil
This question tests the ability to construct a valid GitLab CI/CD YAML pipeline that uses a base Docker image, defines ordered stages, performs a pre-stage network check, and handles Docker image build, tag, and push operations.
Question
- Take a source Docker image named alpine
- Define two stages named build and push
- Check network connectivity before the stages run
- Fetch the latest Docker image
- Create a new Docker image and push it to the registry
- Tag the new Docker image as the latest version Drag and drop the code snippets from the bottom onto the blanks in the GitLab CI configuration to achieve the requirements for the design. Not all options are used.
Exhibit
Explanation
This question tests the ability to construct a valid GitLab CI/CD YAML pipeline that uses a base Docker image, defines ordered stages, performs a pre-stage network check, and handles Docker image build, tag, and push operations.
Approach. The correct configuration uses the top-level 'image: alpine' keyword to set the source Docker image, a 'stages' block listing 'build' then 'push' in order, and a 'before_script' block at the global level to run a network connectivity check (e.g., ping or curl) before any job executes. The build stage job uses 'docker pull' to fetch the latest image and 'docker build' to create the new image, while the push stage job uses 'docker push' to upload the image and 'docker tag ... :latest' followed by another push to tag it as the latest version. The key insight is that 'before_script' at the top level runs before every job across all stages, making it the correct placement for a pre-check validation, while stage ordering in the 'stages' list enforces sequential execution of build before push.
Concept tested. GitLab CI/CD YAML structure - specifically the correct use of 'image', 'stages', 'before_script' (global pre-check), and per-stage job scripts for Docker build/tag/push workflows in a CI/CD pipeline.
Reference. GitLab Docs: https://docs.gitlab.com/ee/ci/yaml/ - keywords: image, stages, before_script, script
Topics
Community Discussion
No community discussion yet for this question.
