Run deploys in parralel with different env vars

Hey,

We deploy to different environments and use env vars and stages to configure the build script that runs like so:

# extract
jobs:
  include:
  - stage: test
    name: lint css
    script: npm run lint:css
  - script: npm run lint
    name: lint
  - script: npm run flow
    name: flow
  - script:
    - npm run test
    name: test
  - stage: uk-builds-development
    if: branch != master
    script: skip
    env:
    - CLUSTERSET_NAME=US-1
   - MORE_ENV=VARS
   deploy:
    - provider: s3
      skip_cleanup: true
      secret_access_key: "$key"
      access_key_id: "$key"
      bucket: "$bucket1"
      acl: public_read
      region: <region1>
      upload_dir: <upload_dir
      local_dir: build
      on:
        all_branches: true
  - stage: us-builds-development
    if: branch != master
    script: skip
    env:
    - CLUSTERSET_NAME=US-1
   - MORE_ENV=VARS
    deploy:
    - provider: s3
      skip_cleanup: true
      secret_access_key: "$key"
      access_key_id: "$key"
      bucket: "$bucket2"
      acl: public_read
      region: <region2>
      upload_dir: <upload_dir
      local_dir: build
      on:
        all_branches: true

And then out npm build runs build.sh which looks something like:

CLUSTERSET_NAME=$CLUSTERSET_NAME
MORE_ENV=$MORE_ENV
npx webpack-cli --mode production --progress -p --colors

The tests run in parallel (super!) but the deploys run sequentially (not super).

We went with build stages because that’s the only way I could see to change env vars per deploy while also changing some properties of the deploy eg. the region.

Is there any way to achieve the same result but have the jobs run in parallel?

Cheers!

Bumping this in the hopes of receiving an answer

I don’t see any reason that the uk-builds-development and us-builds-development stages should be separate.

Oh my word apologies - I’ve made a typo in the crucial moment!

The difference between UK and US builds should be the value of the environment variable:

    env:
    - CLUSTERSET_NAME=UK-1
    env:
    - CLUSTERSET_NAME=US-1`

Apologies - I don’t seem to be able to edit the original post

I believe this configuration will do what you are asking:

jobs:
  include:
  - stage: test
  ⋮
  - stage: deploy
    name: us deploy
    env:
    - CLUSTERSET_NAME=US-1
    deploy:
      - provider: s3
      ⋮
  - name: uk deploy 
    env:
    - CLUSTERSET_NAME=UK-1
    deploy:
      - provider: s3
      ⋮

The jobs in the deploy stage will run independently and simultaneously.

That’s worked wonderfully!

Thank you very much @BanzaiMan, that’s made a big difference for us

1 Like