Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Bitbucket
Bitbucket Cloud

Documentation

Deploy using SCP

This guide will show you how to deploy your files to a remote host using the SCP-deploy pipe in Bitbucket Pipelines.

For this example we created simpleReactApp and deployed it to production with theSCP-deploy pipe.

A full end-to-end example is available in thisrepository if you prefer a more hands-on experimentation with deploying to your host using Pipelines and Pipes.

Prerequisites:

  • Remote host with ssh access

  • Bitbucket repository

Step 1: Configure your Bitbucket repository for the project

To define the following twovariables, in the repository, selectRepository settingson the left sidebar. Under the Pipelines section, selectRepository variables.

Name

Value

USER

The user that is configured on the remote host.

SERVER

The remote host to transfer the files to.

You can define these variables at the deployment environment, repository, or workspace level.

Step 2: Configure your SSH keys

Set up anSSH key in Bitbucket Pipelines or provide it as a secured variable:SSH_KEY (seeusing multiple ssh keys). By default, theSCP-deploy pipe will use your configured SSH key andknown_hosts file.

Step 3: Configure your server

On your remote host (sometimes called a production node):

  • Allow users to connect on HTTP (port 80).

  • Configure ssh keys to allow access.

Here's a configuration example using NGINX on the server. Note: this configuration is intended for demo purposes only.

server { listen 80; listen [::]:80; root /var/www/scp-deploy/html; index index.html index.htm; server_name <your_host_public_DNS_name>, <example.com>; location / { try_files $uri $uri/ =404; }}

Step 4: Setup your CI/CD configuration

Edit your bitbucket-pipelines.yml file. To find out more about theSCP-deploy pipe, select it in the right of the editor.

Add these steps to bitbucket-pipelines.yml :

image: node:10.15.3pipelines: default: - step: name: Build and test caches: - node script: - npm install - npm test - npm run build artifacts: - build/** - step: name: Deploy artifacts using SCP to PROD deployment: production script: - pipe: atlassian/scp-deploy:0.3.3 variables: USER: $USER SERVER: $SERVER REMOTE_PATH: '/var/www/scp-deploy/html' LOCAL_PATH: 'build/*'

This configuration allows you to run tests, build, and deploy your files to the remote host using theSCP-deploy pipe after each push to the Bitbucket repository. Learn more abouthow to edit and configure your Bitbucket pipelines configuration.

Note:You can use file globbing in theLOCAL_PATH to specify the files you want to deploy.

For example, you can use$BITBUCKET_CLONE_DIR default variable - the absolute path of the directory that the repository is cloned into within the Docker container:

LOCAL_PATH: '${BITBUCKET_CLONE_DIR}'     # copy the current directory and all included files. Keeps the parent directory structure.LOCAL_PATH: '${BITBUCKET_CLONE_DIR}/*'    # copy the contents from the current directory.

Or you can specify your'custom/local/path':

LOCAL_PATH: 'custom/local/path'    # copy your custom directory and all included files. Keeps the parent directory structure.LOCAL_PATH: 'custom/local/path/*'   # copy the contents from your custom directory.

If you specify the'/' (slash) as theLOCAL_PATH variable, it will copy all files from the root build container filesystem. We recommend using a relative directorycustom/local/path or${BITBUCKET_CLONE_DIR}/* if you want to copy all files from the build directory.

Step 5: Deploy application to production

Push your application’s code to your Bitbucket repository which will trigger the pipeline. You can then select Pipelines  to check pipeline progress. 

Now you can focus on building your great application, everything else is handled with Bitbucket Pipelines.

Was this helpful?

Still need help?

The Atlassian Community is here for you.

[8]ページ先頭

©2009-2025 Movatter.jp