1
votes

We're using VSTS to build and release our front end code (JS + WebPack)

We now have 2 separate builds for Dev and Test.

Build tasks:

  1. Get sources
  2. npm install
  3. npm build dev
  4. Archive dist files
  5. Copy Publish Artifact: drop

(+release pipelines)

In the "Triggers" section in VSTS, it is posible to listen to multiple branches.

It seems unnecessary to have to so similar builds (?) when we have individual release pipelines.

The only different is step 3 (npm build dev and npm build test)

My question is: Is it possible to dynamically at build time determin the build environment based on source branch that triggered the build? And dynamically set arg in step 3?

2

2 Answers

1
votes

Sure, you can add a PowerShell task to check source branch (using built-in variable, such as Build.SourceBranch), then add or modify the variable through Logging Commands (e.g. Write-Host "##vso[task.setvariable variable=currentEnv;]Dev").

After that you can use that variable (currentEnv) in npm task (e.g. Command and arguments: run $(currentEnv))

0
votes

Thank you @starian :+1:

Ended up creating a branch selector shell script (.sh)

branchSelector

The script

buildTask

VSTS Build tasks

triggers

VSTS Triggers (default development)