pool.demands for deployment jobs not working correctly in azure yaml pipelines

Copper Contributor

I have an azure pipeline yaml that my final goal is to manage and control the agent of the agent pool that launch each job of my pipeline. What I did is get and store in a variable de agent name that I want to use throw all my pipeline, and with the pool.demands property restrict the agent that can launch each job.

My specific case is that for jobs of type job is working exactly how I want to, but not for deployments job type. Here is a real example:

 

stages:
- stage:
  pool:
    name: "MyAgentPool"
  jobs:
    - job: GetCurrentAgentPool
      displayName: Save current agent pool
      steps:
        - checkout: none
        - task: PowerShell@2
          name: GetAgentNameJob
          displayName: Store current agent pool
          inputs:
            targetType: 'inline'
            script: echo "##vso[task.setvariable variable=AgentName;isoutput=true]$(Agent.Name)"
    
    - job:
      displayName: job type
      dependsOn:
        - GetCurrentAgentPool
      variables:
        AgentName: $[ dependencies.GetCurrentAgentPool.outputs['GetAgentNameJob.AgentName'] ]
      pool:
        name: "MyAgentPool"
        demands: Agent.Name -equals  $(AgentName)
      steps:
        - script: echo $(AgentName)

    - deployment:
      displayName: deployment type
      environment:  MyEnvironment
      dependsOn:
        - GetCurrentAgentPool
      variables:
        AgentName: $[ dependencies.GetCurrentAgentPool.outputs['GetAgentNameJob.AgentName'] ]
      pool:
        name: "MyAgentPool"
        demands: Agent.Name -equals  $(AgentName)
      strategy:
        runOnce:
          deploy:
            steps:
              - script: echo $(AgentName)

If I execute this yaml, the result is that the 1º and 2º job is executed with no problem, but 3º one, the deployment job throws an error with no description. Here the result:

image.png

 

And if I drill down to see the error, as I said, there is nothing:

 

image.png

 

My first thought is that the variable "AgentName" is not storing correctly the value, but if I remove de pool.demand tag line then I can see that the value is correctly set with the print screen echo.

0 Replies