npm install fails in circle ci (angular cli project) - circleci

I have created a project in Angular cli. I want to do CI using circle ci. The project is uploaded in Bitbucket and is correctly picked by Circle CI. The build fails though. Following is the config.yml (picked CircleCI's sample.yml and changed it (added ng test). I assume that the package.json created by angularcli earlier would install AngularCLI.
version: 2
jobs:
build:
#working_directory: ~/mern-starter
# The primary container is an instance of the first list image listed. Your build commands run in this container.
docker:
- image: circleci/node:7.10.0
# The secondary container is an instance of the second listed image which is run in a common network where ports exposed on the primary container are available on localhost.
#- image: mongo:3.4.4
steps:
- checkout
- run:
name: Update npm
command: 'sudo npm install -g npm#latest'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Install npm wee
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
test:
docker:
- image: circleci/node:7.10.0
#- image: mongo:3.4.4
steps:
- checkout
- run:
name: Test
command: ng test
#- run:
# name: Generate code coverage
# command: './node_modules/.bin/nyc report --reporter=text-lcov'
#- store_artifacts:
# path: test-results.xml
# prefix: tests
#- store_artifacts:
# path: coverage
# prefix: coverage
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build
filters:
branches:
only: dev
Error
#!/bin/bash -eo pipefail
npm install
module.js:472
throw err;
^
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (mod
I see the following line after npm install step so I suppose process-nexttick-args is already installed.
process-nextick-args#1.0.7 node_modules/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/node_modules/process-nextick-arg

Following configuration worked for me. I used CircleCI 2.0. I am still refining it and might change the answer in future.
version: 2
jobs:
build:
working_directory: ~/angularcli
# The primary container is an instance of the first list image listed. Your build commands run in this container.
docker:
- image: circleci/node:6-browsers
environment:
CHROME_BIN: "/usr/bin/google-chrome"
steps:
- checkout
- run:
name: Install node_modules with npm
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: Install angularcli
command: sudo npm install -g #angular/cli#latest
- run:
name: Run unit tests with karma
command: ng test
- store_test_results:
path: test-results.xml
In addition to above script, set singleRun flag to true in karma.conf.js singleRun: true so that Karma exits after running all the test cases. Without this flag, Karma runs in continuous mode, the ng test stop doesn't end and test fails after timeout.

Related

How to run a build command with CircleCI Node/Express app

I have a backend API via Node/Express and am just starting to learn CI/CD. I am using CircleCI and have a general template set up but can't seem to figure out how to get CircleCi to create a build folder during the process.
Below is my starting circle.yml file:
version: 2.1
jobs:
build:
docker:
- image: circleci/node:12.9.1
steps:
- checkout
- run: echo "npm installing"
- run: npm install
- run: npm run build
test:
docker:
- image: circleci/node:12.9.1
steps:
- checkout
- run: echo "Running test suite (TODO not currently applicable)"
complete:
docker:
- image: circleci/node:12.9.1
steps:
- checkout
- run: echo "Completed build & test process (TODO Add linting checks)"
workflows:
version: 2.1
build_test:
jobs:
- build
I have a build script in my package.json with the following: "build": "tsc".
Running this outside of circleci, it compiles the build folder as I need.
Looking at the status on circleci, everything passes. But the branch does not have the actual build folder.
version: 2.1
jobs:
build:
docker:
- image: circleci/node:12.9.1
steps:
- checkout
- run: echo "npm installing"
- run: npm install
- run: npm run build
- persist_to_workspace:
root: ~/project
paths:
- build
test:
docker:
- image: circleci/node:12.9.1
steps:
- checkout
- run: echo "Running test suite (TODO not currently applicable)"
complete:
docker:
- image: circleci/node:12.9.1
steps:
- checkout
- run: echo "Completed build & test process (TODO Add linting checks)"
deploy:
docker:
- image: circleci/node:12.9.1
steps:
- attach_workspace:
at: ~/project
- run:
name: Deployment Step
command: |
#!/bin/sh
ls build
workflows:
version: 2.1
build_test:
jobs:
- build
- test:
requires:
- build
- complete:
requires:
- test
- deploy:
requires:
- complete
When the build script runs, creates a folder called build that you can persist in order to use in another job. In the new job called deploy, it calls the folder where the build folder is, so now you can for example send this folder to a server.

When trying to deploy to S3 on Circle CI, error is `The user-provided path build does not exist.`

I'm trying to set up continuous deployment on Circle CI.
I've successfully run my build script, which creates a build folder in the root directory. When I run the command locally to sync with s3, it works fine. But in Circle CI I can't get the path to the build folder.
I've tried ./build, adding working_directory: ~/circleci-docs in the deploy job, and printing the working directory in a test run, which was /home/circleci/project, so I tried manually using /home/circleci/project/build and that didn't work either.
This is my CircleCI config.yml file:
executors:
node-executor:
docker:
- image: circleci/node:10.8
python-executor:
docker:
- image: circleci/python:3.7
jobs:
build:
executor: node-executor
steps:
- checkout
- run:
name: Run build script
command: |
curl -o- -L https://yarnpkg.com/install.sh | bash
yarn install --production=false
yarn build
deploy:
executor: python-executor
steps:
- checkout
- run:
name: Install awscli
command: sudo pip install awscli
- run:
name: Deploy to S3
command: aws s3 sync build s3://{MY_BUCKET}
workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
The error message was:
The user-provided path build does not exist.
Exited with code 255
I got it to work!
In the build job I used persist_to_workspace and the deploy job attach_workspace (both are under steps)
- persist_to_workspace:
root: ~/
paths:
- project/build
- attach_workspace:
at: ~/

Bad substitution: Bringing key in env over to yml file

I am currently running tests from Cypress in CircleCI for my project. I have my record key for Cypress and I need to store it in an process.env file and bring it over to my config.yml file.
I can't really find anything too specific to my need.
I am getting an error as well:
/bin/bash: ${process.env.CYPRESS_RECORD_KEY}: bad substitution
Here is my code:
.circleci/config.yml/
version: 2
jobs:
build:
docker:
- image: cypress/browsers:chrome67
steps:
- checkout
- run:
name: Install Dependencies
command: npm ci
paths:
- ~/.npm
- ~/.cache
- run: npm install --save-dev cypress
- run: node_modules/.bin/cypress verify
- run: node_modules/.bin/cypress run --browser chrome --record ${process.env.CYPRESS_RECORD_KEY}
.env
CYPRESS_RECORD_KEY = <my_key_here>
Re-tried it by moving things around and still gets same error:
version: 2
jobs:
build:
docker:
- image: cypress/browsers:chrome67
steps:
- checkout
- run:
name: "setup custom environment variables"
command:
echo ${process.env.CYPRESS_RECORD_KEY} >> $BASH_ENV
- run:
name: Install Dependencies
command: npm ci
paths:
- ~/.npm
- ~/.cache
- run: npm install --save-dev cypress
- run: node_modules/.bin/cypress verify
- run: node_modules/.bin/cypress run --browser chrome --record $BASH_ENV
Not sure how to correctly bring it over.
As of 7/9/2019 Cypress still does NOT support headless Chrome (which is what runs in the command line only) being recorded. Even though I have the record key I cannot use it because they still have not been able to have headless Chrome support recording or anything like Electron can when in headless mode.
My only solution is that I run tests I want recorded locally but other than that I am just letting them pass in the command line and hoping Cypress just implements recording soon.

cypress ci missing libgtk-x11-2.0.so.0

I am running Cypress with circle ci. It works when using the orb, but this does not. I am trying to start both of my client server along with node server. It seems like I am missing a package in the docker container or something.
I am willing to change back to use the cypress orb, but I am not sure how to set it up to have both servers running before running cypress/run
> If you are using Docker, we provide containers with all required dependencies installed.
----------
/home/circleci/.cache/Cypress/3.1.5/Cypress/Cypress: error while loading shared libraries: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
----------
Platform: linux (Debian - 8.11)
Cypress Version: 3.1.5
Here are the steps:
docker:
# specify the version you desire here
- image: circleci/node:10.8.0
- image: circleci/postgres:9.6
environment:
POSTGRES_USER: postgres
POSTGRES_DB: dnb
- image: redis
- image: cypress/base:10
environment:
TERM: xterm
steps:
- checkout
- restore_cache:
keys:
- v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
- v1-deps-{{ .Branch }}
- v1-deps
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
# cache NPM modules and the folder with the Cypress binary
paths:
- ~/.npm
- ~/.cache
# - run:
# name: Run test
# command: npm test -- --coverage --forceExit --detectOpenHandles --maxWorkers=10
# no_output_timeout: 3m
# - run:
# name: Send codecov coverage report
# command: bash <(curl -s https://codecov.io/bash) -f coverage/lcov.info -t
- run:
name: run client server
command: npm start
background: true
- run:
name: Pull server
command: cd && git clone ....git && ls
- run:
name: run node server
command: cd && cd ..i && npm install && npm run dev:prepare && npm start
background: true
- run: npm run cypress:run
You aren't actually executing cypress in the cypress/base:10 docker image.
See the CircleCI docs for multiple images:
In a multi-image configuration job, all steps are executed in the container created by the first image listed.
You should try this instead:
docker:
# specify the version you desire here
- image: cypress/base:10
environment:
TERM: xterm
- image: circleci/postgres:9.6
environment:
POSTGRES_USER: postgres
POSTGRES_DB: dnb
- image: redis

Share result of a step between different jobs in CircleCi

I have this generic config.yml in CircleCi.
version: 2
jobs:
build:
docker:
- image: circleci/node:7.10
steps:
- checkout
- run: npm install
- run: npm run lint
deploy:
machine: true
steps:
- checkout
- run: npm install
- run: npm run build
As you can see, npm install is called twice, which is a duplication of tasks.
Is it possible to share the results of npm install between the 2 jobs?
The end goal is to install the package only one time.
What you're looking for is Workspaces: https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs

Resources