node.jsdockernpmaws-lambdabitbucket-pipelines

Do I have to npm install in every step in a bitbucket pipeline that I need to use an npm command


I have a bitbucket pipelines yml that I have step for running my test script and a step to run a serverless deploy script. Do I need to npm install at each step or will the first npm install carry through and suffice for each subsequent step. Further than that, what is happening under the hood? I know Docker container is created; does each step just update the container?

- step:
        name: Test and Build
        script: 
          - npm install --no-package-lock
          - npm run test
    - step:
        name: Deploy Serverless
        script:
          - npm i serverless -g
          - npm install --no-package-lock
          - npm run deploy

Solution

  • You can use dependency caching. See the documentation.

    In case of node:

    bitbucket-pipelines.yml
    pipelines:
      default:
        - step:
            caches:
              - node
            script:
              - npm install
              - npm test
    

    The first time this pipeline runs it won't find the node cache and so the npm commands will download dependencies from the internet. For future builds, our service will have them cached, so loading them into your build will be quicker.

    Caches will automatically get cleared every week. You can also do this manually.