jsongitlabgitlab-ci-runner

glab release create fails: cannot unmarshal upload.ReleaseAsset


I am trying to fix a GitLab runner that creates releases with glab release create, but it is failing.

Within .gitlab-ci.yml:

glab release create $CI_COMMIT_TAG --assets-links "{\"name\":\"Release\", \"url\":\"$CI_SERVER_URL/$CI_PROJECT_PATH/-/jobs/$JOB_ID/artifacts/file/artifacts.zip?inline=false\"}"

This expands to
(copied from GitLab jobs log, so some quotes may be missing, and I had to redact the URL):

glab release create 0.3_test_release14 --assets-links {"name":"Release", "url":"https://gitlab.______.com/_____/_____/_____/-/jobs/2037359/artifacts/file/artifacts.zip"}

But then ends in error:

ERROR: failed to parse JSON string: json: cannot unmarshal object into Go value of type []*upload.ReleaseAsset

I cant figure out where this went wrong...

This even happens if I reduce it to:

> glab release create  0.3_test_release14 --assets-links "{}"  
ERROR: failed to parse JSON string: json: cannot unmarshal object into Go value of type []*upload.ReleaseAsset

Solution

  • Oh, I finally found out.
    It is even written correctly on the man page.

    As the error message also points out (if only I knew more about Go.. ), an array is expected:
    Go value of type []*upload.ReleaseAsset

    The same can also be confirmed on the man page, an array is expected.

    Adding angular brackets will clear the error.

    #Minimal example:
    glab release create  0.3_test_release14 --assets-links "[{}]"
    
    #Long example:
    glab release create $CI_COMMIT_TAG --name "Release ${CI_COMMIT_TAG}" --notes "$CI_COMMIT_TAG_MESSAGE" --assets-links "[{\"name\":\"Release\", \"url\":\"$CI_SERVER_URL/$CI_PROJECT_PATH/-/jobs/$JOB_ID/artifacts/file/artifacts.zip?inline=false\"}]"