# cancel_pipeline_functions.yml .cancel_pipeline_template: image: alpine:latest before_script: - apk add --update curl - | cancel_pipeline () { curl --request POST --header "PRIVATE-TOKEN: ${MY_PAT_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${CI_JOB_ID}/cancel" } # .gitlab-ci.yml image: alpine:latest include: cancel_pipeline_functions.yml test1: stage: test extends: .cancel_pipeline_template script: - echo "This job will cancel the pipeline" - cancel_pipeline