mardi 15 décembre 2020

Gitlab-CI.yaml file not executing if-statement in script when failing

I am trying to write an if statement that will take the exit code and echo a message if the test job fails. In my code, I am intentionally failing my tests so that I can grab the exit code in the script that builds our container that our tests run in. We don't need output if the test is passing. However, when I run this, its just printing out the code in the job's terminal in Gitlab, and not actually executing the if statement. Below is the script code in our gitlab-ci.yaml file, and the if statement at the bottom of the script.

    - >
      docker run
      --rm -i
      --env-file=automate.env
      --network host
      -v ${PWD}/secrets.dec.json:/opt/app/secrets.dec.json
      -v ${PWD}/reports:/opt/app/reports/
      registry.gitlab.com/company/libraries/automate:${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA}
      /bin/bash -c "config && automate -r"
      - if [ $? != "0"] then echo "Failing build!" fi;

Aucun commentaire:

Enregistrer un commentaire