Handle build's parent context cancelation correctly
What does this MR do?
This fixes a problem that I've only really seen manifest as a flaky test issue:
When the build's parent context is canceled, which happens from the trace (read: when a user cancels a job via the UI), we handle this and return a specific BuildError and state.
A build's parent context cancellation can cascade to child contexts and that cancelation can result in it appearing as though the build finished with a failure, rather than it being cancelled, due to a race existing on which signal we handle first.
Why was this MR needed?
In particular, it can fix this flaky test:
=== RUN TestBuildLogLimitExceeded/pwsh/canceled_job
time="2023-03-23T19:48:52Z" level=warning msg="Custom Executor binary - \"cleanup\" stage" cleanup_std=err job=0 project=0
time="2023-03-23T19:48:52Z" level=warning msg="Mocking execution of: []" cleanup_std=err job=0 project=0
time="2023-03-23T19:48:52Z" level=warning cleanup_std=err job=0 project=0
job_output_limit.go:75:
Error Trace: C:\GitLab-Runner\builds\gitlab-org\gitlab-runner\executors\custom\job_output_limit.go:75
C:\GitLab-Runner\builds\gitlab-org\gitlab-runner\executors\custom\job_output_limit.go:131
C:\GitLab-Runner\builds\gitlab-org\gitlab-runner\executors\custom\job_output_limit.go:102
Error: Should be in error chain:
expected: %!q(**common.BuildError=0xc0000c2088)
in chain: "prepare environment: context canceled. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information"
"context canceled"
Test: TestBuildLogLimitExceeded/pwsh/canceled_job
What's the best way to test this MR?
It's difficult to have a test for this due to it being racey.