Dor Shamay
Dor Shamay

Reputation: 435

Azure DevOps Pipelines- incorrect value in variables declaration

I am using the CI/CD capabilities of Azure DevOps in order to build our micro-services.

One of the tasks I have inside the pipeline is a Bash Task that assign & execute variable declaration for further use in the same job.

When trying to gather the variable after the declaration I'm getting the output {.

The file I'm trying to read its data assigned to a variable is a JSON file, contains a JSON formatted data.

The file called pipeline_1.json, just to make sure that its inside the folder I need before trying to read it. ls command

That is the command that takes the output to the variable. Variable assign

And finally the output. Output of command

My insight was its printing only the first line of the JSON file because its formatted but when tried to format it as simple text it gives the same results

Upvotes: 0

Views: 295

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35514

Based on your description, it seems that you need to get the value in the Json file.

You can try to use the following bash script:

For example:

Json file:

{
  "AA": {
    "BB": "TEST",
    "CC": "XXX"
  }
}

Bash script:

token1=($(jq -r '.AA.BB' pipeline_1.json))

echo "##vso[task.setvariable variable=token1;]$token1"

Then you can get the correct value in the json file.

Upvotes: 1

Related Questions