The GitHub integration allows you to manage your Platform.sh environments directly from your GitHub repository.
- Create a new environment when creating a branch or opening a pull request on GitHub.
- Rebuild the environment when pushing new code to GitHub.
- Delete the environment when merging a pull request.
To integrate your Platform.sh project with an existing GitHub repository, you first need to generate a token on your GitHub user profile. Simply go to your Settings, then select
Developer settings and click
Personal access tokens. Here you can
Generate a new token
Give it a description and then ensure the token has the following scopes:
- To integrate with public repositories:
- To integrate with your own private repositories:
- To integrate with your organization’s private repositories:
Copy the token and make a note of it (temporarily).
Note that for the integration to work, your GitHub user needs to have permission to push code to the repository.
Note that only the project owner can manage integrations.
Open a terminal window (you need to have the Platform.sh CLI installed). Enable the GitHub integration as follows:
platform integration:add --type=github --project=PLATFORMSH_PROJECT_ID --token=GITHUB-USER-TOKEN --repository=USER/REPOSITORY
PLATFORMSH_PROJECT_IDis the project ID for your Platform.sh project
GITHUB-USER-TOKENis the token you generated in step 1
USERis your github user name
REPOSITORYis the name of the repository in github (not the git address)
Note that if your repository belongs to an organization, use
platform integration:add --type=github --project=abcde12345 --token=xxx --repository=platformsh/platformsh-docs
--fetch-branches: Track and deploy branches (true by default)
--prune-branches: Delete branches that do not exist in the remote GitHub repository (true by default)
--build-pull-requests: Track and deploy pull-requests (true by default)
falseto have Platform.sh build the branch specified in a PR.
trueto build the result of merging the PR. (
--pull-requests-clone-parent-data: Set to
falseto disable cloning of parent environment data when creating a PR environment, so each PR environment starts with no data. (
--base-url: Only set if using GitHub Enterprise, hosted on your own server. If so, set this to the base URL of your private server (the part before the user and repository name).
The CLI will create the necessary webhook for you when there’s correct permission set in the given token.
Note that the
--prune-branches option depends on
--fetch-branches being enabled. If
--fetch-branches is disabled,
--prune-branches will automatically be set to false, even if specifically set to true.
If you see the message
Failed to read or write webhooks, you will need to add a webhook manually:
- Copy the hook URL shown in the message.
- Go to your GitHub repository and click Settings, select the Webhooks and Services tab, and click Add webhook.
- Paste the hook URL, choose application/json for the content type, choose “Send me everything” for the events you want to receive, and click Add webhook.
You can now start pushing code, creating new branches or opening pull requests directly on your GitHub repository.
Note that if you have created your account using the GitHub oAuth Login then in order to use the Platform CLI, you will need to setup a password .
You can then verify that your integration is functioning properly using the CLI command
Environments based on GitHub pull requests will have the correct ‘parent’ environment on Platform.sh; they will be activated automatically with a copy of the parent’s data.
However, environments based on (non-pull-request) branches cannot have parents; they will inherit directly from
master and start inactive by default.