# Yarn Javascript

# Setting up your first CI pipeline

Delta CI expects a .delta.yml file in your repository to read your CI config from. If you have a package.json, and have defined scripts like build or test. The config file .delta.yml is as simple as the following.

docker: deltacidocker/node:14
steps:
  - yarn install --frozen-lockfile
  - yarn run test
1
2
3
4

The reason why we added when.changed is because npm ci will try to re-build node_modules every time it runs, even when it is not needed.

# Run your config first time

Once you have committed your .delta.yml file into your git repo and pushed it. Delta CI will start executing it immediately. During the first run, it will need to download the docker image as well as the dependencies. Once you have finished the first run, all subsequent runs will be much faster.

As you may have noticed, there's no caching setup in the config. Unlike other CIs, we don't require you to configure it yourself. Instead, we just keep the disk persistent between build runs, just like your dev environment.

# How to run a deployment job on the main branch, only if my test is successful?

jobs:
  test:
    docker: deltacidocker/node:14
    steps:
      - yarn install --frozen-lockfile
      - yarn run test
  deploy:
    docker: deltacidocker/node:14
    after: test
    branch:
      only: production
    steps:
      - yarn install --frozen-lockfile
      - yarn run deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Environment Variables

There are two ways to set environment variables with Delta CI. Normally you set the env vars under your job in the .delta.yml config. If you want the env var to be a secret, you simply head over to the Workflows page in the dashboard and set them there. More about that further down. Note that the environment variables will only be available to the steps in the job you defined them in, not globally.

# Example with environment variables

jobs:
  "Test and Build":
    docker: deltacidocker/node:14
    env:
      DATABASE_URL: postgresql://prisma:[email protected]:5432/prisma
      SENTRY_ORG: "delta-ci"
      SENTRY_PROJECT: "delta-api"
    steps:
      - yarn install --frozen-lockfile
      - yarn run test
      - yarn run build
1
2
3
4
5
6
7
8
9
10
11

# Secrets

If you want to add a secret environment variable in your jobs, simply click your way to the Workflows page in the dashboard and you should be able to set secret environment variables there. This can be important for third-party auth tokens, Deploy Keys, or some other sensitive data you want to make available for the jobs.

# Allocate more hardware resource for a job

By default, we allocate 4vCPU and 8 GB of RAM for each job. Depends on your use case, you might want to adjust it. You have full control over the allocation as long as you don't exceed your maximum allowance.

docker: openjdk:11
machine:
  vcpu: 8
  mem_mb: 16000 #16GB
steps:
  - yarn run test:parallel
  - yarn run build
1
2
3
4
5
6
7
Last Updated: 2/1/2021, 6:50:36 PM