JSON Vars extention
Extention provides additional Azure pipeline tasks that gives ability to read content of JSON file and set its properies as pipeline variables.
JsonVars task
Running on Node.js (Cross-patform)
Example
test.json
{
"glossary":{
"title":"example glossary",
"GlossDiv":{
"title":"S",
"GlossList":{
"GlossEntry":{
"ID":"SGML",
"SortAs":"SGML",
"GlossTerm":"Standard Generalized Markup Language",
"Acronym":"SGML",
"Abbrev":"ISO 8879:1986",
"GlossDef":{
"para":"A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso":[
"GML",
"XML"
]
},
"GlossSee":"markup"
}
}
}
}
}
pipeline.yaml
trigger:
- master
pool:
vmImage: ubuntu-latest
stages:
- stage:
jobs:
- job: json_output
steps:
- task: JsonVarsV2@0
name: jsonOutput
inputs:
jsonFilePath: '$(System.DefaultWorkingDirectory)/test.json'
envPathSeparator: '.'
isOutput: true
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "$(glossary.GlossDiv.GlossList.GlossEntry.GlossTerm)"
- job: read_json
dependsOn: json_output
variables:
- name: glossary
value: $[ dependencies.json_output.outputs['jsonOutput.glossary.GlossDiv.GlossList.GlossEntry.GlossTerm'] ]
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "$(glossary)"
Console Output
json_output
Starting: PowerShell
Standard Generalized Markup Language
read_json
Starting: PowerShell
Standard Generalized Markup Language