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

Cancelot not cancelling builds in progress #386

Open
langri-sha opened this issue Mar 29, 2020 · 4 comments · May be fixed by #614
Open

Cancelot not cancelling builds in progress #386

langri-sha opened this issue Mar 29, 2020 · 4 comments · May be fixed by #614

Comments

@langri-sha
Copy link

langri-sha commented Mar 29, 2020

Affected builder image

gcr.io/cloud-builders-community/cancelot

Expected Behavior

Cancelot should be cancelling running builds.

Actual Behavior

The filters are not matching any running builds, even though some are currently in progress.

Steps to Reproduce the Problem

  1. Create a trigger for a GH repository matching any branch
  2. Add the following build step:
  - name: 'gcr.io/$PROJECT_ID/cloud-builders/cancelot'
    id: 'Cancelot'
    args: [
      '--current_build_id', '$BUILD_ID',
      '--branch_name', '$BRANCH_NAME',
      '--same_trigger_only'
    ]
  1. Push a change to a branch
  2. Wait for the build to change status to WORKING
  3. Push a change to the same branch
  4. Once Cancelot runs subsequently, the filters do not return any matching builds that are in progress

Additional Info

Step output for initial build:

2020/03/29 10:33:38 Starting cancelot
2020/03/29 10:33:38 Going to fetch current build details for: 338be4dd-2763-425e-9463-73d04fc923e7
2020/03/29 10:33:38 Going to check ongoing jobs for branch: fix/use-day-arithmetic-for-dst-robustness
2020/03/29 10:33:38 Builds filter created: 
		
		build_id != "338be4dd-2763-425e-9463-73d04fc923e7" AND 
		source.repo_source.branch_name = "fix/use-day-arithmetic-for-dst-robustness" AND 
		status = "WORKING" AND 
		start_time<"2020-03-29T10:33:15.545550039Z" AND
		trigger_id = "9e080861-0f43-4fbe-88f3-3123a45394dc"
2020/03/29 10:33:39 Ongoing builds triggered by 9e080861-0f43-4fbe-88f3-3123a45394dc for fix/use-day-arithmetic-for-dst-robustness has size of: 0

Step output for subsequent build:

2020/03/29 10:31:51 Starting cancelot
2020/03/29 10:31:51 Going to fetch current build details for: c8f63287-7f94-4527-9ee4-d5181675a8b8
2020/03/29 10:31:51 Going to check ongoing jobs for branch: fix/use-day-arithmetic-for-dst-robustness
2020/03/29 10:31:51 Builds filter created: 
		
		build_id != "c8f63287-7f94-4527-9ee4-d5181675a8b8" AND 
		source.repo_source.branch_name = "fix/use-day-arithmetic-for-dst-robustness" AND 
		status = "WORKING" AND 
		start_time<"2020-03-29T10:31:29.481194096Z" AND
		trigger_id = "9e080861-0f43-4fbe-88f3-3123a45394dc"
2020/03/29 10:31:52 Ongoing builds triggered by 9e080861-0f43-4fbe-88f3-3123a45394dc for fix/use-day-arithmetic-for-dst-robustness has size of: 0
@siberex
Copy link

siberex commented Apr 8, 2020

Looks like something is wrong with filters here, so cloudbuild SDK returns empty list for ongoing builds.

Probably API was changed since then, and branch name is now available in Source.RepoSource.Revision.BranchName property:
https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_default_substitutions

Also this will not work with GitHub App builds (because they in fact are sourced from storage bucket).

I am using simple bash script instead of cancelot to cancel previous cloud builds, it bypasses those issues. Also it fetches target branch from current build id and works for Github-sourced builds (filtering by substitutions.BRANCH_NAME).

Adapted version to mimic cancelot args is here:
https://gist.github.com/siberex/bb0540b208019382d08732cc6dd59007

Usage:

steps:
  - id: 'cancel previous builds'
    name: 'gcr.io/cloud-builders/gcloud-slim:latest'
    entrypoint: 'bash'
    args: ['path/to/cancelot.sh', '--current_build_id', '$BUILD_ID', '--same_trigger_only']
  • Pros: no need to push Cancelot to Container Registry
  • Cons: you need to put script in your repo with your cloudbuild.yaml (path/to/cancelot.sh is relative to workspace, not to cloudbuild.yaml)

@derekperkins
Copy link

Is this still a problem?

siberex added a commit to siberex/snippets that referenced this issue Jan 13, 2022
@kelly-tock
Copy link

yes, it still does not work.

@DmitryBara
Copy link

Does your cloud build trigger configured in global region?
Otherwise such builders as slackbot, cancelot could not see information about your build

@p-jahn p-jahn linked a pull request Apr 2, 2023 that will close this issue
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 a pull request may close this issue.

5 participants