I have configured a pipeline that uses an environment approve-on-PRD
with a REST API call in "Approval and Checks" to check external dependencies before allowing the Deploy stage to run.
- stage: Vars
jobs:
- job: SetVars
steps:
- checkout: none
- bash: |
echo "Ref ID: 12345"
echo "##vso[task.setvariable variable=RefId,isOutput=true]$ref_id"
name: SetVars
- stage: DeployToAzure_PRD
dependsOn: [Vars]
condition: and(not(failed()), not(canceled()), or(eq('${{ parameters.DeployToAzure }}', true), ne(variables['Build.Reason'], 'Manual')))
jobs:
- deployment: DeployToAzure_PRD
condition: and(not(failed()), not(canceled()))
environment: approve-on-PRD
workspace:
clean: all
variables:
EnvTag: prd
RepoId: [ stageDependencies.Vars.SetVars.outputs['SetVars.RefId'] ]
url=/refIds/$(RefId)
In the url, the RefId
should be applied. However, it seems the variable is not passed to this agentless job. The job simply does not do anything and I do not see any logs.
I guess what I try to achieve is not possible, would there be another workaround? Using variable group, e.g. ?
Would it possible to use string manipulation inside the url like: ${{split('/split/refId', '/')[-1]}}
Variables within the stage and job are currently not available in the Checks + Approval Gates. I raised this question last week specifically for this reason and opened this discussion with Microsoft. I'm trying to get Microsoft to address this as a bug, because this capability works in Release pipelines.
You have a few options:
Create a Variable Group and link to the REST API check. This would mean you'd have an environment for each check and the check highly specialized for a given target.
Sprint 215 introduced a capability that would allow you to use output-variables from previous stages in the deployment gate. In your case, you could change the HEADER, BODY or QueryString of your REST API call to reference the output variable. For example the body of your REST API check can refer to stage variables using $(<Stage>.<Job>.<OutputVariable>)
:
Example body:
{
"RepoId": "$(Vars.SetVars.RefId)"
}
Example query-string: /refIds/$(Vars.SetVars.RefId)