4

I have recently started working with CI using Bitbucket Pipelines. I have managed to connect using my SFTP server, creating API public & private keys and adding them to my server using SSH.

Now, when I run the build it will upload all my files to the correct folder. But I am having a problem that running a package.json command from the script "yarn build" is doing absolutely nothing.. nothing is in the root folder.

What am I missing or doing wrong? Locally everything works just fine same goes for uploading files.

My bitbucket-pipeline.yaml:

# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:10.15.3

pipelines:
  branches:
    develop:
    - step:
        name: Lets push the data to the Server.
        caches:
        - node
        script:
          - pipe: atlassian/sftp-deploy:0.4.1
            variables:
                USER: $SFTP_username
                PASSWORD: $SFTP_password
                SERVER: $SFTP_host
                REMOTE_PATH: /var/www/html/pipeline-http/test-website/
                DEBUG: 'true'
    - step:
        name: Build and test website and deploy.
        caches:
          - node
        script:
          - yarn install
          - yarn test-build
        artifacts:
          - assets/**
Galanthus
  • 1,958
  • 3
  • 14
  • 35
  • 1
    what do you mean by nothing is in the root folder? – Ivan Milisavljevic Jul 22 '19 at 20:45
  • Druze, When I run "yarn test-build" on my computer, Webpack will create a "assets" folder with the compiled CSS and JS files. However, when I run it using the CI and running the command the folder is not created or files are not there at all. – Galanthus Jul 22 '19 at 20:46
  • Did you manage to fix this, I've recently experienced the exact same issue. – Charlie Nov 20 '19 at 19:52

1 Answers1

2

Your pipelines steps are in wrong order.

Bitbucket pipelines are executed in the cloud which means, you have to build your project first, than copy everything to the server (since it cant really copy and build your project on your server)

For your case, this should be correct solution

  branches:
    develop:
    - step:
        name: Build and test website and deploy.
        caches:
          - node
        script:
          - yarn install
          - yarn test-build
        artifacts:
          - assets/**
    - step:
        name: Lets push the data to the Server.
        caches:
        - node
        script:
          - pipe: atlassian/sftp-deploy:0.4.1
            variables:
                USER: $SFTP_username
                PASSWORD: $SFTP_password
                SERVER: $SFTP_host
                REMOTE_PATH: /var/www/html/pipeline-http/test-website/
                DEBUG: 'true'


Ivan Milisavljevic
  • 2,048
  • 2
  • 13
  • 21
  • I have tried this now for some reason the build never continues to the second step this is my output. + yarn test-build yarn run v1.13.0 $ NODE_ENV=development BROWSERSLIST_ENV=development webpack -d --config ./webpack/webpack.config.babel.js [hardsource:8656a567] Writing new cache 8656a567... [hardsource:8656a567] Tracking node dependencies with: package-lock.json, yarn.lock. DONE Compiled successfully in 3673ms9:02:46 PM Use Ctrl+C to close it Keeps loading "test-build": "NODE_ENV=development BROWSERSLIST_ENV=development webpack -d --config ./webpack/webpack.config.babel.js" – Galanthus Jul 22 '19 at 21:05
  • 1
    there is something funky going on with test-build, try removing it just to test our it your code runs on the server – Ivan Milisavljevic Jul 22 '19 at 21:12
  • Ah, it was the "Browsersync" by commenting it out everything works. Hvala ti – Galanthus Jul 22 '19 at 21:19
  • Need one more tip, how to exclude node_modules & src and for instance package.json. – Galanthus Jul 22 '19 at 21:20
  • 1
    Just add them to .gitignore and clear the git cache – Ivan Milisavljevic Jul 22 '19 at 21:23
  • 1
    Nemas frku :). If its easier for you, we can switch to chat – Ivan Milisavljevic Jul 22 '19 at 21:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196836/discussion-between-galanthus-and-ivan-milisavljevic). – Galanthus Jul 22 '19 at 21:24