Skip to content

ci: cancel previous test_plans implementation & fix cancel CI task#22861

Merged
auspham merged 1 commit intosonic-net:masterfrom
auspham:austinpham/37065882-ci-cancel-all-testplans-before-start
Mar 23, 2026
Merged

ci: cancel previous test_plans implementation & fix cancel CI task#22861
auspham merged 1 commit intosonic-net:masterfrom
auspham:austinpham/37065882-ci-cancel-all-testplans-before-start

Conversation

@auspham
Copy link
Contributor

@auspham auspham commented Mar 11, 2026

Description of PR

PREREQUISITE: #23101 to be merged

Summary: PRs that triggered multiply with /azpw run don't have the clean up resources by default. This will make sure for every new pipeline start, we will try to clear previous test plans from Elastictest to optimise resource utilisation

This PR also fix the problem where pressing the 'Cancel' button doesn't cancel the testplan/job

Fixes # (issue) 37065882

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

There are 2 problems:

  1. When trigger /azpw run and there is a running pipeline. The new run will not cancel previous test plans. Which led to duplicated test plans for the same PR.
  2. If the user want to cancel the pipeline by pressing the 'Cancel' button, the current behavior doesn't let user cancel.

How did you do it?

For 1. Introduce #23101 mechanism to cancel all the related pipeline before starting the test plan. This will make sure that before the pipeline start, all the related resources previously is cleaned up

For 2. This PR implement a guard condition that cancel the job when the Cancel button pressed.

How did you verify/test it?

Verified manually

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from 9d9dfae to 61ff9ec Compare March 11, 2026 02:47
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from 61ff9ec to d6036a6 Compare March 12, 2026 00:32
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from d6036a6 to b983bca Compare March 13, 2026 05:06
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from b983bca to 80f7367 Compare March 17, 2026 02:22
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham
Copy link
Contributor Author

auspham commented Mar 18, 2026

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham
Copy link
Contributor Author

auspham commented Mar 18, 2026

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from 80f7367 to 81740db Compare March 18, 2026 04:27
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from 81740db to a656a21 Compare March 18, 2026 05:09
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from a656a21 to 933fb87 Compare March 18, 2026 07:55
@auspham auspham added Request for 202505 branch Request for 202511 branch Request to backport a change to 202511 branch and removed Request for 202511 branch Request to backport a change to 202511 branch labels Mar 23, 2026
@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from 499df51 to 8c3a59a Compare March 23, 2026 01:34
@mssonicbld
Copy link
Collaborator

/azp run

@github-actions github-actions bot requested a review from wangxin March 23, 2026 01:34
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Austin Pham <austinpham@microsoft.com>
@auspham auspham force-pushed the austinpham/37065882-ci-cancel-all-testplans-before-start branch from 8c3a59a to cbac654 Compare March 23, 2026 01:35
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- stage: Test
dependsOn: Pre_test
condition: and(succeeded(), in(dependencies.Pre_test.result, 'Succeeded'))
condition: and(succeeded(), not(canceled()), in(dependencies.Pre_test.result, 'Succeeded'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to add not canceled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is to stop the job being run while press cancel. Since we overwrite the condition statement, it is not following the default cancellation process anymore. So we need to specifically declare it.

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops#why-is-my-build-still-running-after-i-canceled-it

image

Copy link
Contributor

@xwjiang-ms xwjiang-ms left a comment

Choose a reason for hiding this comment

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

LGTM

mssonicbld pushed a commit that referenced this pull request Mar 23, 2026
What is the motivation for this PR?
Currently, when running a new testplan, there is no safety check to cancel all the previous dangling job.

This add the ability to test_plan.py to cancel all related job with PR number using cancel_pr. However this PR does not add the call, only the implementation. The real call will be implemented in #22861

How did you do it?
Added a cancel_pr method that hits Elastictest endpoint API to cancel all previous job for the same PR

How did you verify/test it?
Verified locally and manually using CI
Signed-off-by: Austin Pham <austinpham@microsoft.com>
Signed-off-by: mssonicbld <sonicbld@microsoft.com>
vrajeshe pushed a commit to vrajeshe/sonic-mgmt that referenced this pull request Mar 23, 2026
What is the motivation for this PR?
Currently, when running a new testplan, there is no safety check to cancel all the previous dangling job.

This add the ability to test_plan.py to cancel all related job with PR number using cancel_pr. However this PR does not add the call, only the implementation. The real call will be implemented in sonic-net#22861

How did you do it?
Added a cancel_pr method that hits Elastictest endpoint API to cancel all previous job for the same PR

How did you verify/test it?
Verified locally and manually using CI
Signed-off-by: Austin Pham <austinpham@microsoft.com>
Signed-off-by: Venkata Gouri Rajesh Etla <vrajeshe@cisco.com>
@auspham auspham merged commit ead4791 into sonic-net:master Mar 23, 2026
18 checks passed
@auspham
Copy link
Contributor Author

auspham commented Mar 24, 2026

TODO: cherry-pick into 202505 and 202511

mssonicbld added a commit that referenced this pull request Mar 25, 2026
What is the motivation for this PR?
Currently, when running a new testplan, there is no safety check to cancel all the previous dangling job.

This add the ability to test_plan.py to cancel all related job with PR number using cancel_pr. However this PR does not add the call, only the implementation. The real call will be implemented in #22861

How did you do it?
Added a cancel_pr method that hits Elastictest endpoint API to cancel all previous job for the same PR

How did you verify/test it?
Verified locally and manually using CI

Signed-off-by: Austin Pham <austinpham@microsoft.com>
Signed-off-by: mssonicbld <sonicbld@microsoft.com>
Co-authored-by: Austin (Thang Pham) <austinpham@microsoft.com>
@mssonicbld
Copy link
Collaborator

@auspham PR conflicts with 202505 branch

@mssonicbld
Copy link
Collaborator

@auspham PR conflicts with 202511 branch

vmittal-msft pushed a commit that referenced this pull request Mar 26, 2026
* ci: cancel previous test_plans implementation

Signed-off-by: Austin Pham <austinpham@microsoft.com>

* fix: added default parameters for cancel pr pipeline

Signed-off-by: Austin Pham <austinpham@microsoft.com>

---------

Signed-off-by: Austin Pham <austinpham@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants