Handling non 0 exit code

Hi,

I’m trying to setup a pipeline for a Salesforce DX project. I’ve followed this guide online and it’s been pretty good so far: https://www.ktema.org/2018/03/17/circleci-sfdx-multiple-org-shapes/.
now what I’m trying to do is paramterize my build such that a certain command is run with specific credentials based on the branch I’m on. This is what I have so far:

         - run:
            name: isProd
                  command: |
                       if [[ "$CIRCLE_BRANCH" == "master" ]]; 
                            then
                                 echo "master"
                     fi
          - run:
              name: isDev
                  command: |
                       if[[ "$CIRCLE_BRANCH" == "develop" ]]; 
                          then
                             echo "dev"
                      fi

Problem is - i get a non zero exit code when one of these is not true, causing the build to fail. Any ideas?

Yep. Just execute true after your conditional:

if [[ "$CIRCLE_BRANCH" == "develop" ]]; then
    echo "dev"
fi

# Always succeed
true

This is what I have in my yml file:

                if [[ "$CIRCLE_BRANCH" == "master" ]]; 
                then
                   echo "hello world"
                fi
                true

When “$CIRCLE_BRANCH” evaluates as something other than master, I get this error:

       /bin/bash: if[[ master == develop ]]: command not found

Looks like this is the same question :smiley:

I know I’m quite late to the party here, but thought I’d post a response in case anyone else runs into a similar issue.

You’re missing a space between if and [[ so bash is looking for a command named if[[

For clarity, it should be:

if [[ "$CIRCLE_BRANCH" == "develop" ]]; 
then
    echo "dev"
fi
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.