Closed
Description
Describe the bug
Invalid character when trying to construct a JSON output from a script, in this case, a specific value generates the error.
To Reproduce
- Create workflow:
jobs:
debug-without-variable:
runs-on: ubuntu-latest
steps:
- name: Create JSON and set output
id: create_json
uses: actions/github-script@v7
with:
script: |
return [
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"value": "InstrumentationKey=GUID_GOES_HERE;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=GUID_GOES_HERE"
},
{
"name": "EventHubConnectionString__fullyQualifiedNamespace",
"value": "abc"
}
];
debug-with-variable:
runs-on: ubuntu-latest
environment: dev-europe
steps:
- name: Create JSON and set output
id: create_json
uses: actions/github-script@v7
with:
script: |
return [
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"value": "${{ vars.AZURE_APPLICATIONINSIGHTS_CONNECTION_STRING }}"
},
{
"name": "EventHubConnectionString__fullyQualifiedNamespace",
"value": "abc"
}
];
- create an envirnoment "dev-europe" and add a single variable
AZURE_APPLICATIONINSIGHTS_CONNECTION_STRING
with valueInstrumentationKey=GUID_GOES_HERE;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=GUID_GOES_HERE
- run the workflow and see results.
Expected behavior
No error in the github action.
Screenshots
This value, the output of the script, will be in the subsequent steps, I skip those for clarity. We have two outcomes:
Success:
Failure:
SyntaxError: Invalid or unexpected token
##[error]Unhandled error: SyntaxError: Invalid or unexpected token
at new AsyncFunction (<anonymous>)
at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35424:16)
at main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35522:26)
at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:35497:1
at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:35553:3
at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35556:12)
at Module._compile (node:internal/modules/cjs/loader:1529:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
at Module.load (node:internal/modules/cjs/loader:1275:32)
at Module._load (node:internal/modules/cjs/loader:1096:12)
Additional context
My context is, that I am preparing a set of settings for my Application to be deployed in Azure Function App. Those are the settings I will need later. I was adding one after another variables for the app configuration and stumbled on the App Insights connection string.