Search code examples
aurelia

Effecting the environment flag from within the build


I have an Aurelia CLI app that uses the CLI in conjunction with Gulp to build. I was asked to enable a feature where we pass the name of the branch we're building and determine an environment from that. I was hoping to do this within my gulp tasks. I think I can achieve it through our Continuous Integration, but, I'd like to do it from within gulp if possible. Is this possible?


Solution

  • We use Visual Studio Team Services for Continuous Integration. I added a Powershell Script build step to our definition, which, depending on the name of the passed branch, would write a variable with the right environment name. Then, I'm planning to add an additional build step to my definition, to only run when the master branch is being built - to rebuild my source without the testing framework.

    The powershell script we use to write the variables is as follows:

    if ($env:BUILD_SOURCEBRANCHNAME -eq "qa"){
     Write-Output ("##vso[task.setvariable variable=auenv]" + "stage")
    }
    elseif ($env:BUILD_SOURCEBRANCHNAME -eq "master")
    {    
     Write-Output ("##vso[task.setvariable variable=auenv]" + "prod")
    }
    else
    {
     Write-Output ("##vso[task.setvariable variable=auenv]" + "dev")
    }
    

    Then, when it comes time to use it:

    au build --env $(auenv) --version $(Build.BuildNumber) --testable
    

    Finally, we build without the test framework

    au build --env $(auenv) --version $(Build.BuildNumber)
    

    I recognize my solution is out of scope relative to the audience I asked it for. Sorry about that.