A job in a GitLab pipeline ran into a rather cryptic error, mentioning mapping values in a specific line:
`.gitlab-ci.yml`: (): mapping values are not allowed in this context at line 336 column 169
At least the UI shows a tag "yaml invalid", which hints to a problem with the YAML format, but besides this, it is unclear what the error means. At least if this is the first time you run into that kind of error.
Taking a closer look at that specific line 336 reveals that this is within the script context and executes the following shell command:
329 script:
[...]
335 - export sudoershash=$(sha256sum ./conf/mysudoers)
336 - echo -ne "Path: /etc/sudoers.d/mysudoers\nSHA256 Hash: ${sudoershash}" > /tmp/mailcontent
[...}
At first I suspected a problem with the variable (${sudoershash}) inside line 336, but variables are perfectly supported.
By opening the pipeline in the Pipeline Editor and hovering over the marked line 336, an additional information is shown:
Incorrect type. Expected "string | array".
This for me was the final hint I needed. For some reason, the pipeline parser understood the colons (:) in the string as key: value assignment.
By simply changing the colons to an equal (=) character, the pipeline was fixed:
329 script:
[...]
335 - export sudoershash=$(sha256sum ./conf/mysudoers)
336 - echo -ne "Path=/etc/sudoers.d/mysudoers\nSHA256 Hash=${sudoershash}" > /tmp/mailcontent
[...}
Another way to fix it is to remove the white spaces behind the colons:
329 script:
[...]
335 - export sudoershash=$(sha256sum ./conf/mysudoers)
336 - echo -ne "Path:/etc/sudoers.d/mysudoers\nSHA256 Hash:${sudoershash}" > /tmp/mailcontent
[...}
Use the method you prefer :-).
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Observability Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder