Just integrate this task into your pipeline and you will be good to go.
  - job: checkpipelinestatejob
    displayName: 'Check Pipeline state'
    condition: and(succeeded(), eq(variables['Build.Reason'], 'Schedule')) # only check this for scheduled runs (by cron-trigger)
    steps:
    - task: PowerShell@2
      name: 'checkPreviousPipelineRun'
      displayName: 'Check previous pipeline run status'
      env:
          AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
      inputs:
        targetType: inline
        script: |
          # Login to Azure DevOps Extension is happening automatically using ENV AZURE_DEVOPS_EXT_PAT which is set above
          # Set default Azure DevOps organization and project
          az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject) --use-git-aliases true
          # List last pipeline runs (just for easier debugging)
          echo "*** Last five runs of this pipeline:"
          az pipelines runs list --pipeline-ids $(System.DefinitionId) --status all --top 5 --output table
          # Fetch result of the previous scheduled run (--top 1)
          $previousRunResult = $(az pipelines runs list --pipeline-ids $(System.DefinitionId) --status completed --reason schedule --top 1 --query "[].result" -o tsv)
          echo "*** Previous scheduled run of this pipeline was completed with status: $previousRunResult"
          if($previousRunResult -eq "failed")
          {
            throw "*** Previous scheduled pipeline run did not complete successfully. Not running another pipeline. Please cleanup manually and retry."
          }
I hope this helps.