1

Issue

I am trying to use the Gitlab yaml API linting tool on an enterprise instance of Gitlab. However, I am getting an empty response (not just an empty json object, like absolutely zero output).

Steps to duplicate

I am using a stripped version of the sample .yaml file shown on the gitlab CI/CD tutorial page. The file is shown here:

build-job:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"

deploy-prod:
  stage: deploy
  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."

I am using the 1 line curl command as shown on the CI Linting API page.

If I use the command as given (replacing only the filename), I get

$ jq --null-input --arg yaml "$(<.gitlab-ci.yml)" '.content=$yaml' \
| curl "https://gitlab.mycompany.com/api/v4/ci/lint?include_merged_yaml=true" \
--header 'Content-Type: application/json' \
--data @-

I get the output {"message":"401 Unauthorized"}, which is to be expected as the API call requires an API key. I generate an API key in my profile and try again:

$ export TOKEN='xxxxxxxxxx'
$ jq --null-input --arg yaml "$(<.gitlab-ci.yml)" '.content=$yaml' \
| curl "https://gitlab.mycompany.com/api/v4/ci/lint?include_merged_yaml=true" \
--header "Content-Type: application/json PRIVATE-TOKEN=${TOKEN}" \
--data @-

When I run this, the output shows nothing. This is confirmed by a pipe to wc -c which outputs 0.

My expected output should be:

{
  "status": "valid",
  "errors": [],
  "warnings": []
}

Questions:

  1. Why is no response a result of me using my valid API key (This is with a newly generated key)?
  2. How can I fix this, and receive the expected output shown above?
blackbrandt
  • 2,010
  • 1
  • 15
  • 32
  • If you remove everything but the curl command (including the `--data @-` option) do you get the response saying `no content`? `{"error": "content is missing"}` – Adam Marshall Aug 18 '21 at 16:28

1 Answers1

0

Make sure your token as the api scope, as illustrated here.

Without that scope, you would get a 401 Unauthorized, which would not be parsed parsed by jq at all.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250