Deployment of matrix artifacts

Phil Dye's Avatar

Phil Dye

05 Sep, 2016 03:23 PM

I'm trying to figure out how to make two builds (from a matrix, each with a different API url in the environment), each deploy to their respective deployment environments;


environment:
  NODE_ENV: production
  matrix:
    - API_URL: https://PROJECTNAME-dev.azurewebsites.net/
    - API_URL: https://PROJECTNAME.azurewebsites.net/

install:
  - npm install

build_script:
  - npm run deploy

artifacts:
  - path: dist
    name: project-name

 deploy:
- provider: Environment
  name: PROJECTNAME-Dev
  application: project-name
  on:
    branch: master
- provider: Environment
  name: PROJECTNAME-Release
  application: project-name
  on:
    branch: release/*

Currently, I get two build artifacts as expected, but no way to deploy one to PROJECTNAME-Dev and the other to PROJECTNAME-Release. I know I could use $(API_URL) in the artifact name, but when that's a url it's not clean?

Phil

  1. Support Staff 1 Posted by Feodor Fitsner on 05 Sep, 2016 05:23 PM

    Feodor Fitsner's Avatar

    Why would you need two build jobs for that?

    Am I correct to understand that you are trying to deploy to "dev" environment on any push to "master" branch and to "release" environment on "release/*" branch?

  2. 2 Posted by Phil Dye on 05 Sep, 2016 06:00 PM

    Phil Dye's Avatar

    Correct... but also, the environment variable is used in the build, to set a url into the artifact output (it's a ReactJS single page app being built with webpack, so the artifact is a bunch of js). The dev environment points to a dev API, and release to a live API - as static assets, we can't set these values at 'runtime' from the webserver.

  3. Support Staff 3 Posted by Feodor Fitsner on 05 Sep, 2016 06:07 PM

    Feodor Fitsner's Avatar

    OK, then you can solve this problem with a little of PowerShell:

    environment:
      NODE_ENV: production
    
    install:
      - npm install
      - ps: |
          if($env:appveyor_repo_branch -eq 'master') {
            $env:API_URL = 'https://PROJECTNAME-dev.azurewebsites.net/'
          } else {
            $env:API_URL = 'https://PROJECTNAME.azurewebsites.net/'
          }
    
    build_script:
      - npm run deploy
    
    artifacts:
      - path: dist
        name: project-name
    
    deploy:
    - provider: Environment
      name: PROJECTNAME-Dev
      application: project-name
      on:
        branch: master
    - provider: Environment
      name: PROJECTNAME-Release
      application: project-name
      on:
        branch: release/*
    
  4. 4 Posted by Phil Dye on 06 Sep, 2016 08:17 AM

    Phil Dye's Avatar

    Thanks Feodor, works perfectly - great support as always!

    Phil

  5. Phil Dye closed this discussion on 06 Sep, 2016 08:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac