Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set env when job cancelled for hooks #3213

Merged
merged 1 commit into from
Feb 27, 2025
Merged

Set env when job cancelled for hooks #3213

merged 1 commit into from
Feb 27, 2025

Conversation

sj26
Copy link
Member

@sj26 sj26 commented Feb 27, 2025

So that hook behaviour can change when the job has cancelled, either from the platform or because the agent is being stopped, and so its result is likely inconsequential. We have some customers who would like to use this to avoid sending a notification to a system about a result that doesn't matter because it is either incomplete or will be retried.

Alternative to #3201 / PIPE-481.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go fmt ./...)

This could use an additional automated test but I'm not sure how complicated that'll be. But this seems a pretty low-risk change in any case.

I manually tested by adding a post-command hook like this:

if [[ "$BUILDKITE_JOB_CANCELLED" == "true" ]]; then
  echo "Job was cancelled, skipping notifications!"
  exit
fi

echo "Sending notifications ..."

and it worked a treat:

image

That should also cover when the agent is stopped forcefully which also cancels the job.

Sorry, something went wrong.

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
So that hook behaviour can change when the job has cancelled, either
from the platform or because the agent is being stopped, and so its
result is likely inconsequential.
@sj26 sj26 requested a review from a team February 27, 2025 00:00
@sj26 sj26 self-assigned this Feb 27, 2025
Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM!

@sj26 sj26 merged commit f8539b4 into main Feb 27, 2025
1 check passed
@sj26 sj26 deleted the job-cancel-env branch February 27, 2025 03:01
pull bot pushed a commit to MaxMood96/docs-2 that referenced this pull request Mar 6, 2025

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
Introduced by buildkite/agent#3213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants