Skip to content

How To Use

Ryan Valizan edited this page Aug 30, 2020 · 6 revisions

Arguments

  • Live WordPress branch: -b
    wp-git-sync.sh -b $LIVE_BRANCH

  • Development WordPress branch: -d
    wp-git-sync.sh -b $DEV_BRANCH

  • Name of git repository: -g
    wp-git-sync.sh -g $GIT_REPOSITORY_NAME

  • -p Path to project root directory: wp-git-sync.sh -p $PATH_TO_GIT_PROJECT

  • Clean or pull WordPress changes back to Azure DevOps: -r

    • Options:
      • Clean
        This option is great for cron jobs running to pull WordPress changes from your web server. With this option chosen, the new files are added, any changes are committed, and then the they are pushed back to Azure DevOps for the dev team to integrate into their next release.

        Either of these would work for clean:

        # Clean
        `wp-git-sync.sh -r Clean`
        # clean
        `wp-git-sync.sh -r clean`
      • Push
        This option is great for pushing a new release of changes to your WordPress web server. The stage branch, where releases come from, is pulled from Azure DevOps on the WordPress. The web server will then merge any new changes from the stage branch into the wordpress live branch. When the merge is complete, the updated live branch is pushed back to Azure DevOps for the integration back into release.

        Either of these would work for push:

        # Push
        `wp-git-sync.sh -r Push`
        # push
        `wp-git-sync.sh -r push`

    wp-git-sync.sh -r $CLEAN_OR_PUSH

  • Token or password: -t
    Token or password for HTTPS authentication to the git repository

    wp-git-sync.sh -t $GIT_HTTPS_PASSWORD

  • Username: -u
    Username for HTTPS authentication to the git repository

    wp-git-sync.sh -u $GIT_HTTPS_USERNAME


Command

bash ~/wp-git-sync.sh \
  -b sgLive \
  -d sgStage \
  -g $(DevOpsHost)wordpress-ssh-git-ci \
  -p /home/username/public_html/wp-git-sync \
  -t $(DevOpsToken) \
  -u $(DevOpsTokenUser)

Azure Pipeline

YAML Example:
note: This example uses Azure Key store variables

steps:
- task: SSH@0
  displayName: pushChanges
  inputs:
    sshEndpoint: 'agent-to-siteground'
    commands: 'bash ~/wp-git-sync.sh \
    -b sgLive \
    -d sgStage \
    -g $(DevOpsHost)wordpress-ssh-git-ci \
    -p /home/username/public_html/wp-git-sync \
    -t $(DevOpsToken) \
    -u $(DevOpsTokenUser)'

Classic Editor Example:

PipelineScreen

Console Log:

WordPress-SSH-Git-CI

Requirements:

  • Web server have git capability -- think this is the most important one
  • A method to store your secrete variables such as
    • username
    • password/token
  • SSH access to execute scripts on WordPress server
    • note: cron can serve as a slower alternative to SSH
  • Some kind of CI pipeline or cron job to hook into after a branch update event triggers an agent to run the script remotely

What it has:

  • Parameter options for dynamic use
  • Separated functions
  • Is executed through an ssh call to your WordPress web server

What it does is:

  • Check a git repo on a WordPress web server for changes
  • Stashes changes before working on merges
  • Pulls in latest release/master branch from development repository — on Azure DevOps, GitHub, BitBucket, etc.
  • Merges new changes from DevOps into WordPress Live branch
  • Returns WordPress updates and changes using git stash pop
  • Commits the new changes on top of the latest master branch head
  • Pushes WordPress live branch back to the development repository for the team to handle PR to DevOps master.

Essentially, it allows WordPress developers to be more hands off with their shared hosting WordPress server backends, while still fully benefitting from any of the many source control repository and project board sites for git — but while using WordPress at the same time.

Clone this wiki locally