w3resource

Using Yarn for continuous Integration across different CI systems


You can use yarn in various continuous integration systems. In order to speed up builds, you can save the Yarn cache directory across builds.

Using AppVeyor

If you are using AppVeyor, it should be noted that it has Yarn preinstalled; so you do not need to do anything extra to use it as part of your build.

CircleCI

CircleCI has a documentation for using Yarn, this documentation can be found here: https://circleci.com/docs/2.0/yarn/.

Codeship

Codeship Basic has Yarn preinstalled. However, if you are using Codeship Pro (with Docker), it is recommended that you install Yarn, using Yarn's Debian/Ubuntu package.

Travis CI

Travis CI will detect the use of Yarn by the presence of a yarn.lock file in the repository root. If there is a yarn.lock file, Travis will install yarn when it is necessary and then execute yarn as the default install command.

If your installation phase requires more, you will have to install Yarn yourself until it is preinstalled on build images.

We recommend that you lock in a specific version of yarn, this will enable all your builds to use the same version of Yarn, and you can test new Yarn releases before you switch over. Yarn does this by adding the version number to the apt-get install call.

Semaphore

Semaphore preinstalls yarn for every supported version of Node.js, also semaphore does not need any user interaction for yarn cache to work.

To ensure that your local Yarn version matches the one on Semaphore, you will have to configure the setup commands inside your project settings.

SolanoCI

SolanoCI has Yarn preinstalled. Instructions on how to get up and running is contained in here: https://docs.solanolabs.com/ConfiguringLanguage/nodejs/#configuration

GitLab CI

Since GitLab CI uses docker in the background, an image can be specified with yarn pre-installed.

# .gitlab-ci.yml

```image: node:9.4.0```

If you are using a docker image that does not come with a pre-installed yarn, you can also install it after the container has loaded.

# .gitlab-ci.yml

In both cases, it is a good practice to cache your node_modules and .yarn folders. It is also important to speed up your builds.

# .gitlab-ci.yml

```cache:
  paths:
    - node_modules/
    - .yarn```
.

An example .gitlab-ci.yml file that runs a test suite using yarn is shown below. You should save this file to the root of your project and GitLab's CI will do the remaining jobs.

# .gitlab-ci.yml

```image: node:9.11.1

before_script:
  - yarn install

test:
  stage: test
  cache:
    paths:
    - node_modules/
    - .yarn```

Codefresh pipelines

Codefresh uses Docker images in all their steps, hence it is very easy to use any Yarn version in a pipeline.

The pipeline will check out the source code and then run yarn with freestyle steps.

codefresh.yml

```version: '1.0'
stages:
  - prepare
  - test
  - build
steps:
  main_clone:
    title: Cloning main repository...
    stage: prepare
    type: git-clone
    repo: 'codefresh-contrib/react-sample-app'
    revision: master
    git: github
  MyUnitTests:
    title: Unit test
    stage: test
    image: node:11.0
    commands:
      - yarn install
      - yarn test
    environment:
      - CI=true
  MyReactBuild:
    title: Packaging application
    stage: build
    image: node:8.16
    commands:
      - yarn build```

It should be noted that you can use any version of node/yarn that exists in Dockerhub.

Previous: Managing dependencies and upgrading dependencies with Yarn.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/yarn/continuous-integration.php