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
Related
I am trying to run the following pipeline in bitbucket pipelines for a salesforce SFRA project. It is working great until I add a couple more sites to our build setup. I have already added in the 2x and the docker memory of 7128. Are there any other ways to optimize this pipeline so it stops crashing? I also am not positive that the caches step is setup correctly. I had to hide most of the logs for security and privacy.
Here is the error I am getting in the log. This error shows up on the npm run compile:js:prod step every time.
Killed
npm ERR! code ELIFECYCLE
npm ERR! errno 137
And here is my pipeline
image: node:10.18.0
definitions:
services:
docker:
memory: 7128
pipelines:
default:
- step:
caches:
- node
script:
- npm install
- npm test
branches:
develop:
- step:
name: Test Code
script:
- npm install
- npm run lint
- npm test
custom:
deployment-to-staging:
- step:
name: Test Code
script:
- npm install
- npm run lint
- npm test
- step:
name: Deploy To Staging
deployment: staging
size: 2x
script:
- npm install
- npm run compile:svg
- npm run compile:scss:prod
- npm run compile:js:prod
- npm run compile:fonts:prod
- npm run deployCartridges <options hidden>
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: ~/
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.
I'm trying to setup a basic pipeline in Gitlab that does the following:
Run tests command, compile the client and deploy the application using docker-compose.
The problem comes when I'm trying to use npm install.
My .gitlab-ci.yml file looks like:
# This file is a template, and might need editing before it works on your
project.
# Official docker image.
image: docker:latest
services:
- docker:dind
stages:
- test
- build
- deploy
build:
stage: build
script:
- cd packages/public/client/
- npm install --only=production
- npm run build
test:
stage: test
only:
- develop
- production
script:
- echo run tests in this section
step-deploy-production:
stage: deploy
only:
- production
script:
- docker-compose up -d --build
environment: production
when: manual
And the error is:
Skipping Git submodules setup
$ cd packages/public/client/
$ npm install --only=production
bash: line 69: npm: command not found
ERROR: Job failed: exit status 1
I'm using the last docker image, so, I'm wondering whether I can define a new service on my build stage or should I use a different image for the whole process?
Thanks
A new service will not help you, you'll need to use a different image.
You can use a node image just for your build-stage like this:
build:
image: node:8
stage: build
script:
- cd packages/public/client/
- npm install --only=production
- npm run build
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.