0

My Azure DevOps branch has a code coverage policy set up so that PRs must contain 80% diff coverage (i.e. 80% of the modified lines are covered). I am trying to pull via a REST API whether the diff coverage policy passed or not.

I tried using GET https://dev.azure.com/{organization}/{project}/_apis/policy/evaluations?artifactId=vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}&api-version=6.1-preview.1, but in the response, the status of the codecoverage policy is "queued".

I believe this is related to the fact that in my Checks section of my PR, I see two code coverage checks: one check says myrepo/codecoverage is is "Waiting" status, and another says "Coverage status check succeeded for myrepo"

The above API is returning the Waiting codecoverage check but not the successful one. Is this because codecoverage is considered an external service? If so, how can I get the results?

I can get the full code coverage using this API: https://dev.azure.com/{organization}/{project}/_apis/test/codecoverage?buildId={buildId}&flags=7&api-version=6.1-preview.1, but again I am looking for the diff coverage.

Or is there something wrong with the branch policy setup such that the code coverage check is not updating itself and is instead leaving the waiting check and spawning a separate check? Thanks.

1 Answer 1

1

The reason you saw two code coverage checks is because the myrepo/codecoverage status check you specified cannot be found. So it stuck at waiting for the Code coverage status posted from the pipeline. You probably manually entered the myrepo/codecoverage in the Status to check field and have capital letter in myrepo.

The Status to check field at the branch policy page is {name-of-your-pipeline/codecoverage} as stated in this document. But the document doesnot clearly state that name-of-your-pipeline is in lowercase. If your validation pipeline has Uppercase letter in its name, you need to change it to lowercase if you manually enter the Status to check field.

I encountered the same issue at first, for i didnot know that the {name-of-your-pipeline/codecoverage} should be in lowercase. And i manually entered the name of my pipeline with the capital letter in the field.

Actually, if your validation pipeline has been executed and published the coverage before you set up the Status check branch policy. The value of Status to check will automatically find the coverage status and show them in the dropdown list. See below. You can directly select it without enterring the value manually.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, this does look like the problem! I don't have rights to change the "Status to check field" myself (will ask someone else to do so), but I checked on a different repo and branch where the pipeline name is entered in all lowercase, and there was not a duplicate code coverage check, and I was able to successfully use the first REST API mentioned in my original post to get the result of the code coverage policy. Hopefully MSFT will update their documentation to be more explicit. Appreciate your quick help.
Do you get a chance to extract that percentage of Diff Coveage from PR via ADO API endpoint ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.