For loop fails in .giltlab-ci.yaml with "bash: eval: line 85: syntax error: unexpected end of file ERROR: Job failed: exit status 2"

Hello everyone,

I’m wondering if anyone can spot the problem in my .gitlab-ci.yaml. I’m using a for loop and it seems to fail with the error of " bash: eval: line 85: syntax error: unexpected end of file ERROR: Job failed: exit status 2"

Thank you in advance.

my .gitlab-ci.yaml looks like:

before_script:
    - echo "$CI_COMMIT_SHA"
    - sed -i -e "/VERSION/s/version/$CI_COMMIT_SHA/" recipes/*
 
variables:
    STORAGE: "xxxx"
    Recipes: "recipes"

  job1:
  script:
    - for recipe in $(Recipes)/*
      do
        arch="xxxx"
        name=`echo ${recipe} |sed 's/Singularity.//g;s/.simg//g'`
        /bin/bash build.sh -u ${PATH} -t ${arch} ${recipe}
        cp -r ${Recipes}/${name}.simg ${STORAGE}/${arch}/${name}.${arch}.simg.${CI_COMMIT_SHA}
        mv ${Recipes}/${name}.simg ${STORAGE}/
      done
  tags:
    - firstrunner

You need to use - on every line of the script, or use | to have the whole script in a block:

  script:
    - |+
      line1
      line2
      line…

The other thing is the use of $(Recipes). Are you sure you want to capture the output of a subshell here, or did you mean ${Recipes}?

1 Like

@rleigh , yes it’s working now after fixing the issues you mentioned.
Thank you so much!