trying to use set variable from predefined variables and use it in condition for stage in azure devops pipeline
You could use Output variables from previous stages:
Dependencies.stageName.outputs['jobName.stepName.variableName']
Please check the document Jobs can access output variables from previous stages for some more details.
And we need also add a property ;isOutput=true
and name
to the previous stages:
echo "##vso[task.setvariable variable=branchName;isOutput=true]$(resources.pipeline.pipeline1.sourceBranch)"
- task: PowerShell@2
displayName: 'Inline Powershell'
inputs:
TargetType: inline
Script: |
if ("$(alias)" -eq "PipelineA")
{
...
}
pwsh: true
name: powershelltest
Then we could use the Dependencies.stageName.outputs['jobName.stepName.variableName']
as condition in next stage:
- stage: DockerBuildtask
and(succeeded(), or(eq(dependencies.ScanImage.outputs['ScanImage.powershelltest.branchName'], 'refs/heads/develop'), eq(dependencies.ScanImage.outputs['ScanImage.powershelltest.branchName'], 'refs/heads/release'), eq(dependencies.ScanImage.outputs['ScanImage.powershelltest.branchName'], 'refs/heads/feat*.'), eq(dependencies.ScanImage.outputs['ScanImage.powershelltest.branchName'], 'refs/heads/bugfix*.')))
Note: Since you need add the condition on top of all stage, we need update the stages refer from stageDependencies.stageName.jobName.outputs['stepName.variableName']
To Dependencies.stageName.outputs['jobName.stepName.variableName']
Update2:
here i am setting variable(variable.yaml) under deployment not job. so
how would i frame below one
Dependencies.stageNam.outputs['jobName.stepName.variableName'] should
i meniton Deployment as jobName ??
The answer is yes.
You could use the Dependencies.stageName.outputs['jobName.jobName.stepName.variableName']
as condition.
Note: There are two jobName
in the conditions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…