Executors persistence

Hello,

I have a workflow with 3 jobs; build, test, pkg-and-deploy. When build succeed, I want to run test. Which is happening, however I get npm not found. Is it because the changes I did on the machine are not preserved when changing jobs even within the same workflow?

Here my config file:

version: 2.1
executors:
  orion:
    docker:
      - image: ubuntu:18.04
      - image: mysql:5.7.21
        environment:
          - MYSQL_ROOT_PASSWORD=admin
    working_directory: /tmp/build

jobs:
  build:
    executor: orion
    steps:
      - run:
          name: 'Update APT packages'
          command: apt-get -y update > /dev/null
      - run:
          name: 'Install Git for checkout'
          command: apt-get -y install git openssh-client > /dev/null
      - run:
          name: 'Install NodeJS and MySQL'
          command: |
            apt-get install -y curl apt-transport-https > /dev/null
            curl -sL https://deb.nodesource.com/setup_11.x | bash -
            apt-get update
            apt-get install -y nodejs mysql-client > /dev/null
      - checkout
      - run:
          name: 'Initiate MySQL'
          command: mysql --user=root --password=admin --host=127.0.0.1 < docker/mysql/schema.sql
      - restore_cache:
          key: dependency-cache-{{ checksum "package.json" }}
      - run:
          name: 'Install npm'
          command: npm install
      - save_cache:
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - node_modules
  test:
    executor: orion
    steps:
      - checkout
      - run:
          name: 'Run tests'
          command: npm test
      - store_artifacts:
          path: coverage

  pkg-and-deploy:
    executor: orion
    steps:
      - checkout
      - run:
          name: 'Build and package'
          command: |
            npm run pkg
      - deploy:
          name: 'Deploy'
          command: |
            if [ "${CIRCLE_BRANCH}" == "master" ]; then
              # install utils
              apt-get -y install jq curl unzip tar gzip > /dev/null
              curl -LO https://github.com/tcnksm/ghr/releases/download/v0.5.4/ghr_v0.5.4_linux_amd64.zip
              unzip *.zip
              # define version
              VERSION=$(jq -r '.version' package.json)
              export COMMIT=$(git rev-parse --short $CIRCLE_SHA1)
              # deploy
              mkdir -p deploy
              mv dist/*.tgz deploy/
              # release
              ./ghr -u Company -t $GITHUB_TOKEN -c $CIRCLE_SHA1 -delete -prerelease ${VERSION}+${COMMIT} deploy/
            fi

workflows:
  version: 2
  deploy:
    jobs:
      - build
      - test:
          requires:
            - build
      - pkg-and-deploy:
          context: 'bm-deploy'
          requires:
            - build
            - test
          filters:
            branches:
              only: master

Thank you for your help.

Each job runs in a clean container. If you want to carry data between them, Workspaces should help.

https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs

If you want to preserve installed software across jobs, then you may be better off with a custom Docker build. Inherit from ubuntu:18.04 (or whatever other image you prefer) and create a fresh pipeline to ensure this is always healthy.

Try @drazisil’s approach first though, as it is less work to set up.

2 Likes