0

We are moving to GitHub actions (I'm new to actions) and would like to convert the current $json into environment name value pairs. I would like to extract and Name-Value and set/export as windows environment variables. Below is the extract and output of my code. Appreciate any help!

name: Check Build Properties JSON Var File
        id: read-json
        shell: pwsh
        run: |
          $jsonfilePath = Get-ChildItem ${{github.workspace }}\buildtools -Recurse | where {$_.name -match 'buildproperties.json'} |  % { $_.FullName }
          echo "The Value of the declared variable filepath is:- $jsonfilePath"
          #$json = Get-Content $jsonfilePath | ConvertFrom-Json
          $json = Get-Content $jsonfilePath -Raw
          $JsonParameters = ConvertFrom-Json -InputObject $json

This is the current output

the contents of the RAW JSON file from buildTools is: {
  "UPACKPATH": "C:\\Users\\builduser\\upack.exe",
  "NUGETPATH": "C:\\Users\\builduser\\Nuget.exe",
  "NugetPackageUrl": "https://api.nuget.org/v3/index.json",
  "SemVer": '1.0.0.0',
  "PackagePortal": false
}
1

1 Answer 1

1

For this you might Iterate over PSObject properties and use the [Environment]::SetEnvironmentVariable method:

$Json = '{
  "UPACKPATH": "C:\\Users\\builduser\\upack.exe",
  "NUGETPATH": "C:\\Users\\builduser\\Nuget.exe",
  "NugetPackageUrl": "https://api.nuget.org/v3/index.json",
  "SemVer": "1.0.0.0",
  "PackagePortal": false
}'
$Parameters = Convertfrom-Json $Json
$Parameters.PSObject.Properties |Foreach-Object {
    [Environment]::SetEnvironmentVariable($_.Name, $_.Value)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.