How to share apt/pip package installations across all jobs?

Hi guys,
How I can cache(keeping) package installed by the ‘apt-get install’ and ‘pip install’ ? The build I am using the “Machine – docker(service)”
I have two jobs “notification” and “deploy” in my circle.yml.
Below as my circle.yml, my objective is only doing once ‘apt-get install’ or ‘pip install’ then packages can provide for all jobs used.
I don’t want each job are needed to do the same thing(I mean is installed the same packages.
“I must say that too few documents mention this, or are unclear SOPs for the CircleCI 2.0”
Thank you.

defaults: &defaults
  working_directory: ~/ansible_develop
  machine:
    services:
      - docker

version: 2
jobs:
  notification:
    <<: *defaults
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: |
            pip install --upgrade pip
            pip install ansible
            sudo apt-get install pssh
      - run:
          name: Sent the deploy workflow starting email notification
          command: sh $PWD/mail_sent.sh
  deploy:
    <<: *defaults
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: |
            pip install --upgrade pip
            pip install ansible
            sudo apt-get install pssh
      - run:
          name: Sent the mail
          command: sh $PWD/mail_sent.sh

workflows:
  version: 2
  CICD-workflows:
    jobs:
      - notification
      - deploy

Hi, I have changed to the correct format.
Thank you for your kindly reminder.

1 Like

It sounds like you want to avoid the time taken to install things more than once. That’s understandable. The first thing is to try to use the Docker executor if you can - you can separately build a build container, and then use that as a base for your two jobs.

If you have to use the Machine executor, you can share folder(s) between jobs using workspaces (see the docs). That won’t help you with apt-get, but I think it might help you with pip - can you get Pip to store its dependencies in a single specific folder?

Hi,
Okay, I will try.
Thank you for your replying.

Unfortunately, the CircleCI is inside my company. I don’t have the permissions to touch the CircleCI machine(physical, or virtual machine). I can only use it through the CircleCI’s URL.

Can you expand on what you mean by that? It sounds like you are running CircleCI Enterprise on-premises, but if so, how can you access it through the circleci.com URL? I would imagine it has its own IP/URL?

Hi,
I meant is visiting to URL it’s our company owned circleci, not the CircleCI official.
Anyway, I was knew what is the restricted in the CircleCI for my question.
Thank you for your helping.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.