html5 bootstrap template

Post By Abed Putra

How to Setup Pipelines Bitbucket with PHP?

Hi, today I want to tell you how to set up a pipeline on Bitbucket. Have you ever felt the difficulty of uploading files to hosting if there are file changes? or edit files (like PHP or CSS files) directly on the hosting? if there is only one change, it might not be difficult. but what if we change some files consider ten files, it must be very difficult isn't it. therefore here I will tell how to set up a pipeline in bitbucket. So when we make changes to our file we will immediately upload to our hosting after we push with git.

1. Settings Branch pipelines
Visit bitbucket URL (https://bitbucket.org/) Login Go to the settings menu (sidebar menu) Change "Main branch" to branch will deploy

setup pipeline

2. Enable pipelines
Scroll down under "Pipelines" menu click settings Click Enable Pipelines

setup pipeline

3. Adding variable
Scroll down under "Pipelines" menu click Repository variables Add FTP_USERNAME to "type variable" and add your username of FTP to "value variable" Click Add Add FTP_PASSWORD to "type variable" and add your password of FTP to "value variable" Checklist Secured Click Add Add FTP_HOST_PATH to "type variable" and add your path of FTP to "value variable" Click Add

setup pipeline

4. Adding code to bitbucket-pipelines.yml
-------Case 1. if you don't have any data on server Click Pipelines (sidebar menu) Choose a language template Please choose PHP Please add this code to the bitbucket-pipelines.yml editor, don't forget to change "develop" to your main branch.

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN 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: php:7.1.1

pipelines:
  branches:
   develop: #dont forget to change this to your main branch
    - step:
        caches:
          - composer
        script:
          - apt-get update
          - apt-get -qq install git-ftp
          - git ftp init --user $FTP_USERNAME --passwd $FTP_PASSWORD $FTP_HOST_PATH
  • Click commite file
  • Check the result

###

-------Case 2. if already have data on server Click Pipelines (sidebar menu) Choose a language template Please choose PHP Please added this code to the bitbucket-pipelines.yml editor, don't forget change "develop" to your main branch.

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN 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: php:7.1.1

pipelines:
  branches:
   develop: #dont forget to change this to your main branch
    - step:
        caches:
          - composer
        script:
          - apt-get update
          - apt-get -qq install git-ftp
          - git ftp catchup --user $FTP_USERNAME --passwd $FTP_PASSWORD $FTP_HOST_PATH
  • Click commit file
  • Check the result

setup pipeline

5. Changing code bitbucket-pipelines.yml to "push "
(because just push changed data, not all data) After no. 4 please change the bitbucket-pipelines.yml to

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN 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: php:7.1.1

pipelines:
  branches:
   develop: #dont forget to change this to your main branch
    - step:
        caches:
          - composer
        script:
          - apt-get update
          - apt-get -qq install git-ftp
          - git ftp push --user $FTP_USERNAME --passwd $FTP_PASSWORD $FTP_HOST_PATH

6. Done