user672009
user672009

Reputation: 4585

Continuous integration pipeline fails with: Exited with code 1

As part of my CircleCi pipeline I want to execute the below command. The idea is that I assert if a file exists and, if it does, then I want to execute some more commands. During my initial testing the file doesn't exists and I expected the entire command to return 0. Any clue about what's wrong?

      command: |
        [[ -e "stacks/docker-compose-${CIRCLE_BRANC}.yml" ]]
         && set -a && source /tmp/workspace/${CIRCLE_BRANCH}.env && docker-compose -f /tmp/workspace/docker-stack.yml -f "stacks/docker-compose-${CIRCLE_BRANC}.yml" config > /tmp/workspace/docker-stack.yml

Upvotes: 0

Views: 2920

Answers (1)

Aserre
Aserre

Reputation: 5062

If the file doesn't exist, then yes, the [[ -e "..." ]] test will return 1 (because it failed).

If having an exit status to 1 breaks your pipeline, you could rewrite your command line, doing something like this :

[[ ! -e "stacks/docker-compose-${CIRCLE_BRANC}.yml" ]]
|| { set -a && source /tmp/workspace/${CIRCLE_BRANCH}.env && docker-compose -f /tmp/workspace/docker-stack.yml -f "stacks/docker-compose-${CIRCLE_BRANC}.yml" config > /tmp/workspace/docker-stack.yml; }

Here, the logic is inverted from your original script :

  • [[ ! -e "stacks/docker-compose-${CIRCLE_BRANC}.yml" ]] : if your file doesn't exist, we exit with exit code 0
  • else, we execute the command inside the next block (exit code 0 if block is successful, else 1)

Upvotes: 1

Related Questions