Azure / pipelines

Enable GitHub developers to trigger Azure Pipelines from a GitHub Actions workflow
MIT License
73 stars 83 forks source link

Question: Delay reporting from ADO #12

Closed awentzel closed 10 months ago

awentzel commented 4 years ago

When running a GH Action for Azure Pipelines the status succeeded in 8 seconds. However, on ADO, it actually continued running for another 16 minutes. Is there a way to delay the reporting back to GH Actions until the true status is returned from ADO?

Thanks,

eric-labelle commented 4 years ago

I am also wondering the same thing. The status check on PRs in Github are based on workflow actions, but the workflow (which only triggers an Azure DevOps pipeline) is always Valid as soon as it successfully launched the Azure DevOps pipeline, even if the ADO pipeline fails or finishes minutes later as you mentioned. Still haven't found a way to get the status.

EDIT: Actually found a way. At the end of your Azure pipeline triggered by GitHub's Action, you can add a POST call to Github's REST API to add a status on the commit that will prevent you from merging in case the build completed in a failure :) https://developer.github.com/v3/repos/statuses/#create-a-status

spowser commented 4 years ago

In the case of waiting for AzDO to finish before the status is returned to Github, would you be paying for 2 agents at that point? GitHub agent kicks off AzDO and sits there doing nothing but still accumulating minutes on your bill?

tjcorr commented 10 months ago

Yes this is designed to fire asynchronously. If you sat waiting for the ADO pipeline to finish you would be paying for 2x the compute. The recommend approach here would be to have the ADO pipeline open a new status check at the beginning of the pipeline and then mark it as pass/fail at the end. Here is a minimal sample ADO yaml pipeline:

trigger: none

variables:
  BUILD_URL: '$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)'
  CHECK_NAME: 'ADO/pipeline'

pool:
  vmImage: ubuntu-latest

steps:
- script: |
    curl -X POST -H "Authorization: Bearer $(GITHUB_PAT)" https://api.github.com/repos/$(GITHUB_REPO)/statuses/$(GITHUB_SHA) -d '{"state":"pending","target_url":"$(BUILD_URL)","description":"Pending security checks","context":"$(CHECK_NAME)"}'
  displayName: 'Create a new status check on a github repo'

- script: echo 0
  displayName: 'Insert your code here'

- script: |
    curl -X POST -H "Authorization: Bearer $(GITHUB_PAT)" https://api.github.com/repos/$(GITHUB_REPO)/statuses/$(GITHUB_SHA) -d '{"state":"success","target_url":"$(BUILD_URL)","description":"ADO Pipeline passed","context":"$(CHECK_NAME)"}'
  displayName: 'Mark status as success'

- script: |
    curl -X POST -H "Authorization: Bearer $(GITHUB_PAT)" https://api.github.com/repos/$(GITHUB_REPO)/statuses/$(GITHUB_SHA) -d '{"state":"failure","target_url":"$(BUILD_URL)","description":"ADO Pipeline failed","context":"$(CHECK_NAME)"}'
  displayName: 'Mark status as failure'
  condition: failed()

This would require that you pass a few variables into the pipeline like