Search code examples
gitlabgitlab-ciwget

How to use wget with header in gitlab_ci build?


How can I use wget adding the $CI_JOB_TOKEN or any other header information during gitlab_ci.yml build?

build:
  stage: build
  before_script:
    - wget --header='JOB-TOKEN: $CI_JOB_TOKEN' https://git.my-company.com/projects/1234/repository/files/file.txt?ref=master

Result:

Pipeline cannot be run.
jobs:build:before_script config should be a string or a nested array of strings up to 10 levels deep

Why? According to: https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html#troubleshooting the wget command with header information should work, in general.


Solution

  • The error … before_script config should be a string or a nested array of strings … indicates that the YAML syntax is not valid. Please use the /-/ci/lint page in your project to correct it.

    For example, this should work (script: is also needed):

      before_script:
          - 'wget --header="JOB-TOKEN: $CI_JOB_TOKEN" "https://git.my-company.com/projects/1234/repository/files/file.txt?ref=master"'
      script:
        - …