Azure Pipelines "The nested task ... can not be used"
You placed a task that itself orchestrates other tasks somewhere it is not allowed to nest - for example a meta-task inside a deployment strategy or another task’s scope. Azure forbids that nesting.
What this error means
The pipeline fails to compile or start with The nested task <name> can not be used, naming a task that is being used inside a context that only accepts regular leaf steps.
##[error]The nested task 'DownloadPipelineArtifact' can not be used in
this context.Common causes
Meta-task used inside a restricted scope
Certain tasks wrap or expand into multiple sub-steps. Inside a deployment job strategy hook or another constrained block, that expansion is not permitted.
Wrong placement within a deployment strategy
Deployment jobs have lifecycle hooks (preDeploy, deploy, postRouteTraffic) with restrictions on which tasks may appear. A nested/meta task in the wrong hook is rejected.
How to fix it
Move the task to a plain step list
Run the task in a normal steps: block of a regular job rather than inside the restricted context.
jobs:
- job: fetch
steps:
- task: DownloadPipelineArtifact@2
inputs:
artifact: dropUse the allowed task in the deployment hook
- Check which tasks the deployment strategy hook permits.
- Replace the nested task with the equivalent leaf task, or move the work to a preceding regular job.
- Pass results forward via pipeline artifacts or output variables.
How to prevent it
- Keep meta/orchestration tasks in regular jobs, not deployment hooks.
- Read the deployment strategy docs for hook restrictions.
- Validate the pipeline after restructuring deployment jobs.