Authorized DevOps and container security practice
Build and validate a GitLab CI pipeline
Add ordered lint, test, and build jobs, validate the YAML, and inspect the outputs from a feature-branch pipeline.
Learning objective
Create a pipeline in an authorized project where failed verification blocks the build and a successful build exposes its expected artifact.
Use only a repository, branch, runner, registry, image, and activity you own or have explicit authorization to review. Use a Gemini tool only with sanitized material your organization approves. The website does not connect to Gemini.
Start with a clear stage boundary
Create a feature branch in the approved training project, then add or update the project’s .gitlab-ci.yml. Match each script to a command that really exists in that project; the sample below assumes package.json provides lint, test, and build scripts and the build writes dist/. Change those names and the artifact path when the sample project differs.
GitLab runs jobs in a stage after the earlier stage has passed. Here, lint and test run in validate. The package stage starts only after both pass. Each job installs from the lockfile with npm ci so that the example uses the project’s recorded dependency versions.
Open Build > Pipeline editor and use its Validate action before pushing. Then push the feature branch and open the pipeline graph. A red job should identify the failed command in its log; a green pipeline should show both validation jobs and the build as passed. Download the dist/ artifact from the build job to confirm it contains the expected training output.
Treat the pipeline as a reviewable change
Commit the pipeline change on the authorized branch and inspect the merge request pipeline before merging. If a controlled test failure is part of the exercise, add it only to the disposable training branch, observe that the later stage is blocked, then remove it and rerun the pipeline. Do not introduce a failure into a protected or production branch.
A successful pipeline means the configured commands completed. It does not automatically publish an image, approve a deployment, or certify the code as secure. Keep deploy and release jobs out of the exercise unless those actions are separately approved.
Controlled examples
Adapt examples only inside your approved project
stages:
- validate
- package
default:
image: node:22-alpine
lint:
stage: validate
script:
- npm ci
- npm run lint
test:
stage: validate
script:
- npm ci
- npm test
build:
stage: package
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 weekControlled practice
Apply the lesson
Training scenario
The approved training fork has package scripts named lint, test, and build. Its build creates dist/. A disposable feature branch is available; no deployment is in scope.
- Add the sample job graph to .gitlab-ci.yml on the approved feature branch and adapt only the values the project requires.
- Validate the YAML in GitLab’s Pipeline editor, then push the branch.
- Inspect the pipeline graph and open each lint, test, and build job log.
- Download the dist/ artifact from the successful build job and confirm it contains the expected training output.
- On a disposable branch only, observe what happens when a test fails, then restore the passing test and rerun.
Check your work: The pipeline editor accepts the configuration, both validate jobs pass before the package stage, job logs show the real commands, and the build artifact matches the expected output.
Learning check
Check your understanding
The test job fails in the validate stage. What should happen to the package job in this example?
Official references
Continue in the lesson sequence. Return to the GitLab and Gemini path.