How do I run Exactly-once semantics jobs on self-hosted runners with Azure Pipelines?

In Azure Pipelines, achieving Exactly-once semantics for your jobs on self-hosted runners can be crucial for ensuring that your tasks run without duplication, especially in scenarios where job execution may be retried or fail. Below is an example of how to configure your Azure Pipeline YAML to achieve this behavior.

trigger: - main jobs: - job: ExampleJob pool: name: SelfHosted steps: - script: echo "Step 1: Running a unique task" displayName: 'Run unique task' continueOnError: false - script: | echo "Step 2: Checking for job execution" # Logic to ensure the task is only executed once, such as checking a database flag or using a unique identifier displayName: 'Ensure Task Is Unique' continueOnError: false

DevOps Azure Pipelines self-hosted runners Exactly-once semantics CI/CD unique jobs