'Unable to pass values between deployment groups using pipeline artifact

I'm unable to pass values between two deployment groups within a single job. Could you please let me know if I'm making any mistake here? Thanks in advance.

Error message: ##[error]Artifact /mnt/dockerData/agents/queue2/workdir/43/new-vars was not found for build 29

jobs:
  - deployment: A
    pool: Agent-1
    strategy:
      runOnce:
        deploy:
          steps:
            - task: AzureKeyVault@2
                  ---

                - bash: |
                    echo "##vso[task.setvariable variable=client-id;isOutput=true;]$(client-id)"
                    
                    mkdir -p $(Pipeline.Workspace)/new-vars
                    echo "$(client-id)" > $(Pipeline.Workspace)/new-vars/client-id

                - publish: $(Pipeline.Workspace)/new-vars
                  artifact: new-vars

  - if <condition>:
    - deployment: B
      pool: Agent-2
      dependsOn: 
        - A

      strategy:
        runOnce:
          deploy:
            steps:
              - download: current
                artifact: new-vars

Error message: ##[error]Artifact /mnt/dockerData/agents/queue2/workdir/43/new-vars was not found for build 29



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source