firebasecontinuous-integrationfirebase-hostingsemaphore-ci

Triggering Firebase deploy after successful Semaphore CI process


I am following the Firebase tutorial on Continuous Integration.

They use travis in their example, my choice of CI is Semaphore Co. I am stuck at firebase deploy --token $FIREBASE_TOKEN step, as I can't seem to find a way to trigger this in any sort of after success hook in Semaphore. They do have after job, but it is triggered on failed builds as well, due to this, I don't want to deploy using that step, I want to only deploy after all tests / builds pass.


Solution

  • Semaphore is exporting a few environment variables which you can use for conditional execution of commands, similarly as you do with $FIREBASE_TOKEN.

    So if you want to add after job command, you can check status of the job, and if it succeed you can execute deploy command, otherwise not. Such command whould look like:

    if [ "$SEMAPHORE_THREAD_RESULT" = "passed" ]; then firebase deploy --token $FIREBASE_TOKEN ; fi
    

    With same system you can add branch name into the "if" statement, and trigger deploy only if you're for example on "master" brach and if build is passed. More info about all available env variables you can find here/

    As alternative you can check Semaphore's build deployment system, which is basically separate job which is triggered after build is finished (and passed). More info about that you can find at official docs.