Reputation: 357
Trying to read values from a file inside gitlab-ci.yml file:
#!/usr/bin/bash
- IN_FILE="base_dir/apps_namespaces.txt"
- echo "IN_FILE = " > $IN_FILE
- while IFS= read -r line || [ -n "$line" ]; do
- echo "Name read from file - " > $line
- done < $IN_FILE
But this script fails with error - "/usr/bin/bash: line 131: read: line: invalid number"
Whereas same logic works in a plain script file, having following code:
#!/bin/bash
while IFS= read -r line || [[ -n "$line" ]];
do
echo "Text read from file: $line"
done < "$1"
when ran this script using command : ./scrpt apps_namespaces.txt
it rans and print each line.
What can be done if needs a long list to be read inside a gitlab-ci yml ?
Upvotes: 0
Views: 14136
Reputation: 1323203
Check if you can emulate this gitlab-ci.yml
loop example, which:
#!/bin/bash
) script:
[...]
- while read line; do
echo $line;
./sireg-linux exec --loader-sitemap-sitemap \"$line\" >> ./output/${line##*/}_out.txt;
done < sitemap-index
Of course, the alternative is to put the logic in a script, called from the pipeline, as documented in gitlab-org/gitlab-runner
issue 2672
This is basic Unix, you just need your script to be executable in your git repo
chmod a+x scripts/test.sh git add scripts/test.sh git commit "fixing permissions" git push
don't put
/usr/bin/env
forsh
norbash
: both are 100% guaranteed to be present as#! /bin/sh
or/bin/bash
ifbash
is installed, or at least a much guaranteed to be there than/usr/bin/env
to exists (and usingenv sh
is not very good security)
Upvotes: 2
Reputation: 357
A better approach which I followed:
put the logic to read file contents inside a script file. And refer this script inside gitlab-ci.yml worked.
It is cleaner and manageable.
Upvotes: 0