Search code examples
gitlabyamlcontinuous-integrationgitlab-ciyq

Error when using yq image in gitlab pipeline job


I have a gitlab pipeline job that extracts the version number from a yaml file using yq tool and then exporting it as an environment variable. I am using mikefarah/yq:4.27.2 as a base image. the pipeline code is:

prepare-version:
  image: mikefarah/yq:4.27.2
  stage: prepare
  script:
   - ver=$(yq '.version' versions.yml)
   - echo "version=${ver}" >> version.env
artifacts:
   reports:
     dotenv: version.env

The pipeline always fails on:

Using docker image sha256:cecdbf2efcf7240d3378dd188844b2b5805420eef692dfb98aa3a1b6d366ef5a for mikefarah/yq:4.27.2 with digest mikefarah/yq@sha256:856f7ab12c58608d422a742a4917e6998ad065d9d48a5b1cd69c3ce8fa80f3fa ...
Error: unknown shorthand flag: 'c' in -c
Usage:
yq eval [expression] [yaml_file1]... [flags]
Aliases:
  eval, e
Examples:
  # Reads field under the given path for each file
  yq e '.a.b' f1.yml f2.yml 
  # Prints out the file
  yq e sample.yaml 

when using

yq '.version' versions.yml

locally with the same yq version everything works fine. But in the pipeline it fails. Any Ideas why this happens?


Solution

  • It was easier to create my own Docker Image of yq since the documentation does not state why exactly this happens.

    FROM amazoncorretto:17.0.7-alpine3.17
    
    RUN wget https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_amd64 -O /usr/bin/yq
    RUN chmod +x /usr/bin/yq