MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings
From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.
With Motoshare, every parked vehicle finds a purpose.
Owners earn. Renters ride.
🚀 Everyone wins.
Okay, here’s a basic GitLab CI/CD YAML (.gitlab-ci.yml) example that demonstrates how the allow_failure configuration option is used, along with an explanation.
The allow_failure keyword in a GitLab CI/CD job definition specifies whether a pipeline should continue running and potentially be marked as successful even if that particular job fails. By default, if any job fails, the entire pipeline is marked as failed, and subsequent stages are typically not executed.
This is useful for:
- Non-critical jobs like code quality checks, linters, or experimental tests whose failure shouldn’t block the main deployment flow.
- Jobs that deploy to non-critical environments.
- Informational scripts.
Example .gitlab-ci.yml with allow_failure:
YAML
# .gitlab-ci.yml
stages:
- build
- test
- deploy
default:
image: alpine:latest
# Job 1: A standard build job that should succeed
build_application:
stage: build
script:
- echo "--- Building Application ---"
- sleep 5
- echo "Application build successful."
- mkdir -p app_binaries
- echo "my_app_v1" > app_binaries/app
# Job 2: A critical test job. If this fails, the pipeline should reflect a problem.
critical_unit_tests:
stage: test
script:
- echo "--- Running Critical Unit Tests ---"
- sleep 8
- echo "Critical unit tests PASSED."
# To see a pipeline failure, uncomment the next line:
# - echo "Simulating critical test failure!"; exit 1
# Job 3: A non-critical or "flaky" test job that is allowed to fail
# without stopping the pipeline or marking the pipeline as failed overall (if other critical jobs pass).
non_critical_lint_check:
stage: test
allow_failure: true # This is the key configuration
script:
- echo "--- Running Non-Critical Lint Check ---"
- echo "Checking code style..."
- sleep 3
- echo "Lint check found some non-critical style issues and will 'fail'."
- exit 1 # Simulate a failure for this non-critical job
# Job 4: Another non-critical job (e.g., an optional test suite)
# This also uses allow_failure and will demonstrate that the pipeline continues.
experimental_feature_test:
stage: test
allow_failure: true
script:
- echo "--- Testing Experimental Feature (allowed to fail) ---"
- sleep 4
- echo "Experimental feature test completed (simulating success for this one, but could fail)."
- exit 0
# Job 5: Deployment job.
# This job will run if 'build_application' and 'critical_unit_tests' succeed,
# even if 'non_critical_lint_check' failed, because it was allowed to fail.
deploy_to_staging:
stage: deploy
script:
- echo "--- Deploying to Staging ---"
- echo "Checking if critical tests passed before deploying..."
- if [ -f "app_binaries/app" ]; then echo "App binary found."; else echo "App binary NOT found! Build might have issues."; exit 1; fi
- echo "Deploying application to staging environment..."
- sleep 10
- echo "Deployment to staging successful."
# This job depends on the success of prior stages' critical jobs.
# If 'critical_unit_tests' failed (and didn't have allow_failure: true),
# this 'deploy_to_staging' job would not run.
Code language: PHP (php)
Explanation:
allow_failure:Keyword:- Used within a job’s definition.
- It accepts a boolean value:
trueorfalse. allow_failure: true: If this job fails, the job itself will be marked as “failed” (often with a warning icon like orange/yellow in the UI), but it will not cause the entire pipeline to be marked as “failed”. Subsequent jobs in later stages (or parallel jobs that don’t depend on it) can still proceed as if this job had succeeded for the purpose of pipeline progression.allow_failure: false(or omitting the keyword): This is the default behavior. If the job fails, the pipeline is marked as “failed”, and typically, jobs in subsequent stages will not run.
build_applicationJob:- A standard job that is expected to succeed. It does not use
allow_failure, so if it failed, the pipeline would fail.
- A standard job that is expected to succeed. It does not use
critical_unit_testsJob:- This job also does not use
allow_failure: true. If this job were to fail (e.g., by uncommentingexit 1), thedeploy_to_stagingjob would not run, and the pipeline would be marked as failed. This represents a critical part of your CI.
- This job also does not use
non_critical_lint_checkJob:allow_failure: true: This is the key demonstration.- The
scriptis designed toexit 1, which means this job will fail. - However, because
allow_failureis true:- The
non_critical_lint_checkjob itself will show a failed status (often with a warning icon). - The overall pipeline can still proceed to the
deploystage and potentially be marked as “passed” or “passed with warnings” if all other critical jobs (likebuild_applicationandcritical_unit_tests) succeed.
- The
experimental_feature_testJob:- Also uses
allow_failure: true. This job is written to succeed in this example, but if it were to fail, it wouldn’t stop the pipeline. This is typical for tests of features that are under development and not yet stable.
- Also uses
deploy_to_stagingJob:- This job is in the
deploystage, which runs after theteststage. - It will execute if
build_applicationandcritical_unit_tests(the critical jobs in preceding stages) have passed. The failure ofnon_critical_lint_checkwill not preventdeploy_to_stagingfrom running because ofallow_failure: trueon the lint check job.
- This job is in the
Key Concepts and Behavior:
- Pipeline Status:
allow_failure: trueprimarily affects the overall pipeline status. The job that fails but is allowed to fail will still be marked as failed individually. - Visual Indication: In the GitLab UI, jobs that fail but have
allow_failure: trueare often displayed with a distinct icon (e.g., orange or yellow warning) rather than a red failure icon that would stop the pipeline. The pipeline itself might show as “passed with warnings.” - Use Cases:
- Linters/Style Checks: Useful if you want to be informed of style issues but not block deployments for minor infractions.
- Non-Critical Tests: For test suites that are known to be flaky or cover less critical aspects of the application.
- Experimental Features: When testing new, unstable features.
- Informational Scripts: Scripts that gather data or generate reports where failure isn’t catastrophic.
- Manual Jobs: Often, manual jobs (like deployments to optional environments) might have
allow_failure: trueif their failure shouldn’t affect the primary outcome of the CI run.
- Within
rules:: Theallow_failureattribute can also be used within arules:block, allowing you to make the failure allowance conditional. YAMLmy_job_with_rules: script: - "exit 1" rules: - if: '$CI_COMMIT_BRANCH == "main"' allow_failure: false # Failure on main is critical - if: '$CI_COMMIT_BRANCH =~ /^feature\//' allow_failure: true # Allow failures on feature branches
Using allow_failure: true provides flexibility in defining which job failures are considered critical for your pipeline’s success and which are merely warnings or informational. It helps maintain a balance between ensuring quality and not being overly restrictive for non-essential checks.