CLI release - Problem with "--assets-link" format

I have a “Release Job” whose script does the following:

    - Write-Output "assets_list.txt:"
    - $assetsContent = Get-Content -Path assets_list.txt
    - Write-Output $assetsContent

    - release-cli create --name "Release $CI_COMMIT_TAG" --description "No description" --ref $CI_COMMIT_TAG --tag-name $CI_COMMIT_TAG --assets-link="$assetsContent"

The “assets_list.txt” variable content is:

[
    {"name":"project1_name.elf","url":"https://gitlab.../project1_name-9fb112c5-jkh.elf"},
    {"name":"project1_name.hex","url":"https://gitlab.../project1_name-9fb112c5-jkh.hex"},
    {"name":"project1_name.map","url":"https://gitlab.../project1_name-9fb112c5-jkh.map"},
    {"name":"project2_name.elf","url":"https://gitlab.../project2_name-9fb112c5-jkh.elf"},
    {"name":"project2_name.hex","url":"https://gitlab.../project2_name-9fb112c5-jkh.hex"},
    {"name":"project2_name.map","url":"https://gitlab.../project2_name-9fb112c5-jkh.map"}
]

As you can see, there are 4 spaces before each “{” (I don’t know if this is a problem).
I am running GitLab Runner on Windows 10 64-bit using PowerShell console.

The problem is when I do the “release-cli” command. The error is:

time="2024-11-29T10:53:47+01:00" level=info msg="Creating Release..." catalog-publish=false cli=release-cli command=create name="Release test" project-id=2081 ref=test server-url="[https://gitlab....](https://gitlab.....)" tag-message= tag-name=test version=0.18.0

(https://gitlab..../jobs/64634#L52)time="2024-11-29T10:53:47+01:00" level=fatal msg="run app" cli=release-cli error="new CreateReleaseRequest: failed to parse assets: 1 error occurred:\n\t* invalid array of assets: \"[ {name:project1_name.elf,url:https://gitlab.../project1_name-9fb112c5-jkh.elf}, {name:project1_name.hex,url:https://gitlab.../project1_name-9fb112c5-jkh.hex}, {name:project1_name.map,url:https://gitlab.../project1_name-9fb112c5-jkh.map}, {name:project2_name.elf,url:https://gitlab.../project2_name-9fb112c5-jkh.elf}, {name:project2_name.hex,url:https://gitlab.../project2_name-9fb112c5-jkh.hex}, {name:project2_name.map,url:https://gitlab.../project2_name-9fb112c5-jkh.map} ]\" invalid character 'n' looking for beginning of object key string\n\n" version=0.18.0

(https://gitlab......./jobs/64634#L53)Cleaning up project directory and file based variables

(https://gitlab..../jobs/64634#L54)ERROR: Job failed: exit status 1

Does anyone know how to solve this problem?
I have been formatting the variable ‘assets_list.txt’ with PowerShell functions like ConvertFrom-Json and ConvertTo-Json but I can’t get it to work.
I hope someone knows how to solve it.
Thanks!
Best regards

NOTE: URLs are shortened to make them easier to read. They are correct at my site

I am having a nearly identical problem. I’ve tested it with a singular asset rather than an array and it fails in the same way, specifically

invalid character 'n' looking for beginning of object key string

Were you able to solve this?

Hello, I have fixed it.

When the release is created using ‘release-cli’, the JSON contained in ‘$assetsContent’ must be formatted for GitLab to understand it.

Doing this, it is fixes:

    - $assetsContent = Get-Content -Path assets_list.txt
    - $assetsContent = ($assetsContent -replace '\s+', '')
    - $assetsContent = $assetsContent -replace '"', '\"'

    - release-cli create --name "Release $CI_COMMIT_TAG" --description "No description" --ref $CI_COMMIT_TAG --tag-name $CI_COMMIT_TAG --assets-link="$assetsContent"

I hope it can help you.
Best regards!!

1 Like

Thanks! I found the same thing and resolved it by escaping the quotation marks firstly for powershell, and then secondly for gitlab (just as you have).

Something like this:

--assets-link "{\`"name\`":\`"ASSET_NAME\`",\`"url\`":\`"ASSET_PATH\`"}"

Unfortunately the gitlab documentation makes no mention of this for powershell:

Their example doesn’t work and needs further processing, replacing characters, like you have done, post conversion to JSON.