Azure-pipelines-tasks: Using dependency variables in custom condition variable expression

Created on 13 Feb 2019  路  12Comments  路  Source: microsoft/azure-pipelines-tasks

Problem description

After setting a variable in a Powershell step using the following code:

Write-Host "##vso[task.setvariable variable=$(VariableName);isOutput=true]$(VariableValue)"

I'm trying to retrieve that variable in a subsequent job for use as a custom condition variable expression:

eq(dependencies.AgentJob1.outputs['SetVariable.ReadyToDeploy'], 'true')

Unfortunately I receive the following error when the agent attempts to start that job:

Exception Message: Unrecognized value: 'dependencies'. Located at position 4 within expression: eq(dependencies.AgentJob1.outputs['SetVariable.ReadyToDeploy'], 'true'). For more help, refer to https://go.microsoft.com/fwlink/?linkid=842996 (type ParseException)
Exception Stack Trace:    at Microsoft.TeamFoundation.DistributedTask.Expressions.ExpressionParser.HandleUnknownKeyword(ParseContext context) in d:\v2.0\P1\_work\7\s\DistributedTask\Client\WebApi\Expressions\ExpressionParser.cs:line 278
   at Microsoft.TeamFoundation.DistributedTask.Expressions.ExpressionParser.CreateTree(ParseContext context) in d:\v2.0\P1\_work\7\s\DistributedTask\Client\WebApi\Expressions\ExpressionParser.cs:line 85
   at Microsoft.TeamFoundation.DistributedTask.Expressions.ExpressionParser.CreateTree(String expression, ITraceWriter trace, IEnumerable`1 namedValues, IEnumerable`1 functions) in d:\v2.0\P1\_work\7\s\DistributedTask\Client\WebApi\Expressions\ExpressionParser.cs:line 18
   at Microsoft.VisualStudio.Services.ReleaseManagement.Server.Processors.PhaseConditionEvaluator.ShouldExecutePhase(IVssRequestContext requestContext, ReleaseEnvironment releaseEnvironment, DeployPhaseSnapshot deployPhaseSnapshot, AutomationEngineInput automationEngineInput) in d:\v2.0\P1\_work\7\s\ReleaseManagement\Service\ReleaseManagement2\Server\Processors\PhaseConditionEvaluator.cs:line 26
   at Microsoft.VisualStudio.Services.ReleaseManagement.Server.Processors.DeployPhaseRunner.Run(Release release, ReleaseEnvironment releaseEnvironment, ReleaseEnvironmentStep deployStep, DeployPhaseSnapshot snapshotToProcess) in d:\v2.0\P1\_work\7\s\ReleaseManagement\Service\ReleaseManagement2\Server\Processors\DeployPhaseRunner.cs:line 208 

It appears from the docs that this available for YAML, and I had hoped it would also be supported in the GUI. Is this not the case or is my syntax just wrong?

Screenshots for context

capture

The "SetVariable" task group is made up of the aforementioned powershell script to set the variable:

capture

Core question

All 12 comments

+1

Hi guys, any updates on this?

I'm trying to get the dependency result as follows:
eq(dependencies.Job1.result, 'Succeeded')

And failing.

Any updates on this? im facing similar issue :)

Any updates?

Same issue over here, getting the same error:
Unrecognized value: 'dependencies'. Located at position 4 within expression

Any progress?

Same issue

Not supported.

Not supported.

Hi @vtbassmatt, what do you mean by "Not supported"?

Designer-based builds don't accept output variables from other jobs. That's a feature only in YAML.

It doesn't work in YAML, either - and yet the documents dated 8/2020 still show it. I'd recommend this be re-opened.

with:
condition: contains(dependencies.preBuild.outputs['SetVarStep.stageVar'], 'wit')
I get:

##[error]Unrecognized value: 'dependencies'. Located at position 10 within expression: contains(dependencies.

@jason-e-gross Sorry for the confusion - cross-stage dependencies need a different syntax depending on whether you're consuming them at stage level or job level.

I see that this topic still has some outdated info, which I'll get corrected. This doc is up to date with respect to the various syntaxes involved.

Stage-level

stages:
- stage: A
  condition: false
  jobs:
  - job: A1
    steps:
    - script: echo Job A1
- stage: B
  condition: in(dependencies.A.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')
  jobs:
  - job: B1
    steps:
    - script: echo Job B1

Job-level consumption

stages:
- stage: A
  jobs:
  - job: A1
    steps:
     - bash: echo "##vso[task.setvariable variable=shouldrun;isOutput=true]true"
     # or on Windows:
     # - script: echo ##vso[task.setvariable variable=shouldrun;isOutput=true]true
       name: printvar

- stage: B
  dependsOn: A
  jobs:
  - job: B1
    condition: in(stageDependencies.A.A1.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')
    steps:
    - script: echo hello from Job B1
  - job: B2
    condition: eq(stageDependencies.A.A1.outputs['printvar.shouldrun'], 'true')
    steps:
     - script: echo hello from Job B2

@vtbassmatt - I'd suggest some clarification here on both this issue the error message that's shown is not at all helpful, and I'm not clear on how your comment resolves this for @jason-e-gross - I am getting a similar error when expanding conditions set as parameters in a template, but the syntax matches your example dependencies.<jobname>.outputs['stepname.outputvar']

Was this page helpful?
0 / 5 - 0 ratings