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

[New command] Command to cancel build pipeline #876

Closed
jopham-sage opened this issue Nov 8, 2019 · 17 comments · Fixed by #1103
Closed

[New command] Command to cancel build pipeline #876

jopham-sage opened this issue Nov 8, 2019 · 17 comments · Fixed by #1103
Labels
Feature Feature Work required. help wanted

Comments

@jopham-sage
Copy link

Is there a command line to cancel build pipeline? I know we can run the pipeline but I want to cancel it also. Thanks

@jopham-sage jopham-sage added the Feature Feature Work required. label Nov 8, 2019
@atbagga atbagga changed the title Cancel build pipeline [New command] Command to cancel build pipeline Nov 11, 2019
@atbagga atbagga assigned atbagga and unassigned atbagga Nov 12, 2019
@geverghe
Copy link
Contributor

geverghe commented Nov 14, 2019

@jopham-sage
Copy link
Author

@geverghe Hi am looking for Azure Dev Ops CLI command to cancel build pipeline. There's a delete CLI command but I think that's deleting the build. I haven't tried that command but I'll test and see. Thanks.

@geverghe
Copy link
Contributor

So there are two elements - there is a build definition delete and there is a build delete. I think this build delete corresponds to canceling the build run. You can potentially give it a shot with az devops invoke to run this api till we build a command

@geverghe
Copy link
Contributor

geverghe commented Nov 15, 2019

Looks like delete, as the verb indicates, deletes the run and therefore stops the run. However, I think your use case is just cancel. @atbagga is looking into the update API and will get back to you on the API that can be used via invoke till we build a full fledged command.

@atbagga
Copy link
Collaborator

atbagga commented Nov 15, 2019

@jopham-sage The API for cancelling the build is documented here.

PATCH https://dev.azure.com/atbagga/atbagga/_apis/build/Builds/120
Request content: {'status': 'Cancelling'}

You can use the following command as a workaround for the time being until this issue is prioritised and we add a command in CLI for the same.

az devops invoke --area build --resource builds --route-parameters buildId=120 project=atbagga --in-file D:/patch.txt  --http-method patch 

Content in patch.txt -

{'status': 'Cancelling'}

@dhilmathy
Copy link
Contributor

@atbagga I would like to take up this.

I am planning to create a new update command. Something like az pipelines build update --status Cancelling. Your thoughts & comments?

@atbagga
Copy link
Collaborator

atbagga commented Jan 21, 2020

@dhilmathy Sorry missed the update. If you are still up for it please share the detailed command signature and go ahead.

@hdiass
Copy link

hdiass commented Oct 13, 2020

Whats the status of this ? Is there any way to cancel or delete a run via cli ?

@dhilmathy
Copy link
Contributor

@atbagga I am planning to introduce a new command called cancel.

Command signature

Command
    az pipelines build cancel : Cancels if build is running.

Arguments
    --id      [Required] : ID of the build.
    --detect             : Automatically detect organization.  Allowed values: false, true.
    --open               : Open the build results page in your web browser.
    --org --organization : Azure DevOps organization URL. You can configure the default organization
                           using az devops configure -d organization=ORG_URL. Required if not
                           configured as default or picked up via git config. Example:
                           https://dev.azure.com/MyOrganizationName/.
    --project -p         : Name or ID of the project. You can configure the default project using az
                           devops configure -d project=NAME_OR_ID. Required if not configured as
                           default or picked up via git config.

Will submit a PR if above command seems fine for you. Thanks!

@atbagga
Copy link
Collaborator

atbagga commented Oct 19, 2020

@dhilmathy Sorry, I am not a maintainer in this repo anymore.
Tagging the owners for attention.. @Azure/azure-devops-cli

@dsfrederic
Copy link

@dhilmathy what's the status of this new command?

I would use this to find a workaround for this outstanding feature request

@dhilmathy
Copy link
Contributor

@dhilmathy what's the status of this new command?

I would use this to find a workaround for this outstanding feature request

@dsfrederic, I'd created the command based on the proposal I'd made earlier. I am waiting for maintainers comment before raising PR.

@dsfrederic
Copy link

@atbagga @elbatk @mitsha-microsoft can any of you guys help us out?

@dhilmathy dhilmathy mentioned this issue Feb 13, 2021
2 tasks
@atbagga
Copy link
Collaborator

atbagga commented Feb 15, 2021

Thanks @dhilmathy for the PR. I see the project owners are added as PR reviewers.

@kasajian
Copy link

@jopham-sage The API for cancelling the build is documented here.

PATCH https://dev.azure.com/atbagga/atbagga/_apis/build/Builds/120
Request content: {'status': 'Cancelling'}

You can use the following command as a workaround for the time being until this issue is prioritised and we add a command in CLI for the same.

az devops invoke --area build --resource builds --route-parameters buildId=120 project=atbagga --in-file D:/patch.txt  --http-method patch 

Content in patch.txt -

{'status': 'Cancelling'}

Had to fix the contents of the patch.txt file to make it valid json. the single quotes changed double quotes. After I did that, it worked:

{"status": "Cancelling"}

Also had to add --org parameter

@duanqn
Copy link

duanqn commented Jan 9, 2023

I just tried this command locally but it does not work as expected. The pipeline status is updated to "cancelling" but it does not cancel the jobs inside. The jobs are still running and taking up build agent machines. What's worse, after the pipeline status is updated to "cancelling", I cannot manually cancel them in the web UI.

@dhilmathy @atbagga Can you confirm this behavior?

@atbagga I am planning to introduce a new command called cancel.

Command signature

Command
    az pipelines build cancel : Cancels if build is running.

Arguments
    --id      [Required] : ID of the build.
    --detect             : Automatically detect organization.  Allowed values: false, true.
    --open               : Open the build results page in your web browser.
    --org --organization : Azure DevOps organization URL. You can configure the default organization
                           using az devops configure -d organization=ORG_URL. Required if not
                           configured as default or picked up via git config. Example:
                           https://dev.azure.com/MyOrganizationName/.
    --project -p         : Name or ID of the project. You can configure the default project using az
                           devops configure -d project=NAME_OR_ID. Required if not configured as
                           default or picked up via git config.

Will submit a PR if above command seems fine for you. Thanks!

@alsastre
Copy link

alsastre commented Jan 9, 2023

In my experience, that depends on your configuration fo the jobs, you have to make sure that the jobs contain the condition not(cancelled()) to ensure they do not run/stop when the pipeline is cancelled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature Work required. help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants