Hi vijay,
Can you share your code to help you? I can bring you an example of pipeline with powershell on jobs and sharing variables between jobs. Starting point with the file example.json:
{
"someKey": "expectedValue",
"anotherKey": "anotherValue"
}
This is the pipeline that you can test Its working fine:
trigger: none
pool:
vmImage: 'windows-latest'
jobs:
- job: Job1
displayName: 'Job 1: Read JSON and set variable'
steps:
- powershell: |
# Read the JSON file
$json = Get-Content -Path example.json | ConvertFrom-Json
# Get a value from the JSON file
$value = $json.someKey
# Set the value as a variable
Write-Host "##vso[task.setvariable variable=someVariable;isOutput=true;]$value"
name: setVariableStep
- job: Job2
displayName: 'Job 2: Validate variable'
dependsOn: Job1
variables:
someVariableFromJob1: $[ dependencies.Job1.outputs['setVariableStep.someVariable'] ]
steps:
- pwsh: |
Write-Host "The variable from Job 1 is: $(someVariableFromJob1)"
# Validate the variable
if ("$(someVariableFromJob1)" -eq "expectedValue") {
Write-Host "The variable is as expected."
} else {
Write-Host "The variable is not as expected."
}
If you run this pipeline will compare the expectedValue on the json file with the job2. Let me know if this help you. Luis
If the information helped address your question, please Accept the answer.