Install
Upload it under Plugins → Add New Plugin → Upload Plugin, then activate.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/fermain/wp2static-addon-gitlab/releases/download/v1.3.0/wp2static-addon-gitlab-private-1.3.0.zipWP2Static GitLab Private Deployment Add-on
Deploy your static WordPress site to a private GitLab repository using the GitLab API. Perfect for Kubernetes environments and CI/CD workflows.
Features
- 🔒 Private GitLab Support - Works with both GitLab.com and self-hosted GitLab instances
- 🚀 Git-Based Deployment - Clones the repository, commits site output, and pushes to the target branch
- 🔀 Automatic Merge Requests - Creates MRs with auto-merge when CI pipeline succeeds
- 📂 Deploy Subdirectory - Deploy into a scoped subdirectory (default:
public/) to protect CI and repo root files - 🔄 Incremental Deployments - Git handles changes; only modified files are committed
- ☸️ Kubernetes Ready - Works in internal Kubernetes environments without internet exposure
- 🛠️ CI/CD Integration - Triggers your GitLab CI/CD pipelines automatically
- 🧪 Connection Testing - Built-in connection test to verify configuration
- 📝 Detailed Logging - Comprehensive logging via WP2Static's logging system
Requirements
- WordPress 5.0+
- WP2Static 7.2+
- PHP 7.4+
- Outbound HTTPS access to your GitLab instance
- GitLab Project Access Token with
apiscope (recommended) or Personal Access Token withapiandwrite_repositoryscopes
Installation
-
Download/Clone this add-on to your WordPress plugins directory:
wp-content/plugins/wp2static-addon-gitlab-private/ -
Activate the plugin in WordPress Admin → Plugins
-
Configure the add-on in WP2Static → GitLab Private
-
Enable the add-on in WP2Static → Add-ons
Configuration
1. Create GitLab Access Token (Project Access Token Recommended)
Option A: Project Access Token (Recommended)
- Go to your target GitLab repository → Settings → Access Tokens
- Create a new token with:
apiscope - Access the authenticated user's APIMaintainerorOwnerrole
- Set an appropriate expiration date
- Save the token securely
Option B: Personal Access Token (Alternative)
- Go to your GitLab instance → User Settings → Access Tokens
- Create a new token with these scopes:
api- Access the authenticated user's APIwrite_repository- Write (push) to repository
- Set an appropriate expiration date
- Save the token securely
2. Find Your Project ID
- Navigate to your target GitLab repository
- Go to Settings → General
- The Project ID is displayed at the top of the page
- Copy this number (e.g.,
12345)
3. Configure the Add-on
Navigate to WP2Static → GitLab Private and fill in:
- GitLab URL: Your GitLab instance URL
- GitLab.com:
https://gitlab.com - Self-hosted:
https://gitlab.yourcompany.com
- GitLab.com:
- Project ID: The numeric project ID from step 2
- Access Token: The personal access token from step 1
- Working Branch: The branch to push deployments to (e.g.,
staging) - Target Branch: Where merge requests will target (e.g.,
master)- MRs are created automatically when the working branch is new
- Deploy Subdirectory: Subdirectory within the repo to receive the site (default:
public) - Commit Message: Message for deployment commits
- Author Name & Email: Git commit author information
4. Test Connection
Click Test Connection to verify your configuration. You should see:
Connection successful! Project: your-project-name
5. Enable in WP2Static
- Go to WP2Static → Add-ons
- Find "GitLab Private" and click Enabled
- The add-on is now active for deployments
Usage
Automatic Deployment
Once configured, the add-on will automatically deploy when you:
- Run a full workflow: WP2Static → Run
- Process the job queue that includes a deploy job
- Use WP-CLI:
wp wp2static deploy
Manual Deployment
You can also trigger deployment manually via WP-CLI:
# Full workflow (detect, crawl, post-process, deploy)
wp wp2static full_workflow
# Deploy only (requires processed site)
wp wp2static deploy
How It Works
When Working Branch Doesn't Exist (First Deployment)
- File Processing: WP2Static generates static files in
wp-content/uploads/wp2static-processed-site/ - Repo Checkout: The add-on shallow clones the repository
- Branch Creation: Creates the working branch from the target branch
- Scoped Sync: Copies the processed site into the configured deploy subdirectory (default
public/)- Optional: If "Delete Orphaned Files" is enabled, the deploy subdirectory is cleaned before copy
- Git Commit & Push: Commits changes and pushes to the working branch with GitLab push options:
- Creates a merge request targeting the target branch
- Sets auto-merge when CI/CD pipeline succeeds
- Automatically removes the working branch after merge
- CI/CD Pipeline: GitLab runs the pipeline on the MR; if it passes, the MR auto-merges
- Deployment: Your pipeline can deploy the merged changes to production
When Working Branch Exists (Subsequent Deployments)
- File Processing: WP2Static generates static files
- Repo Checkout: Shallow clones and checks out the existing working branch
- Scoped Sync: Updates files in the deploy subdirectory
- Git Commit & Push: Commits changes and pushes with
--force-with-lease- Updates the existing branch
- If an MR is open, GitLab automatically updates it with the new commits
- CI/CD Pipeline: Pipeline runs again; MR auto-merges when successful
Example Workflow
Configuration:
- Working Branch:
staging - Target Branch:
master
First deployment:
- Creates
stagingfrommaster→ Pushes → Creates MR → CI passes → Auto-merges → Branch deleted
Second deployment (after branch deleted):
- Creates
stagingfrommasteragain → New MR created → Process repeats
OR if you want to iterate before merging:
- Don't let the MR merge (disable auto-merge temporarily)
- Second deployment updates
staging→ Updates existing MR - Third deployment updates
stagingagain → MR updates again - When ready, enable auto-merge and let pipeline complete
Git Operations
The add-on performs standard git operations server-side:
- Shallow clone via HTTPS with token credential embedding
- Ensure committer name/email are set locally
- Create or fast-forward the target branch
- Copy site output into the deploy subdirectory
git add -A,git commit(no-op if nothing changed), andgit push
Kubernetes Deployment
This add-on is specifically designed for Kubernetes environments:
Advantages
- ✅ No Git Installation Required - Uses API calls instead of git commands
- ✅ Minimal Dependencies - Only requires WordPress and cURL
- ✅ Outbound Only - No inbound network access needed
- ✅ Stateless - No local git repositories or SSH keys to manage
Example Kubernetes Workflow
# WordPress Pod (internal)
WordPress + WP2Static + GitLab Add-on
↓ (HTTPS API calls)
GitLab Repository
↓ (GitLab CI/CD)
Production Deployment
Troubleshooting
Connection Test Fails
"Connection failed (HTTP 401)"
- Check your access token is correct and not expired
- Verify token has
apiandwrite_repositoryscopes
"Connection failed (HTTP 404)"
- Verify the Project ID is correct
- Ensure the token has access to the specified project
"Missing required configuration"
- Fill in all required fields: GitLab URL, Project ID, Access Token, Branch
Deployment Issues
"git push failed"
- Verify token has write access to the target branch (Maintainer or higher if protected)
- Confirm the repository allows HTTPS pushes with access tokens (
oauth2with PAT is supported)
"No files to deploy"
- Run WP2Static crawl first to generate static files
- Check that files exist in
wp-content/uploads/wp2static-processed-site/
Log Analysis
Check WP2Static logs at WP2Static → Logs for detailed error messages:
GitLab Private deployment started
Found 45 files to deploy
Deploying batch 1 of 3
Successfully deployed 20 files to GitLab
GitLab Private deployment completed
Security Considerations
-
Token Type: Use Project Access Tokens instead of Personal Access Tokens when possible for better security isolation.
-
Access Token Storage: Tokens are stored in the WordPress database. Consider using environment variables for enhanced security.
-
Token Permissions: Use minimal required scopes:
- Project Access Token:
apiscope only - Personal Access Token:
apiandwrite_repositoryonly
- Project Access Token:
-
Network Security: Ensure your GitLab instance is accessible over HTTPS.
-
Token Expiration: Set reasonable expiration dates and rotate tokens regularly.
Limitations
- Server Git Required: The WordPress environment must have
gitavailable inPATH - Deploy Scope: Deletions (if enabled) are limited to the deploy subdirectory
- Large Repos: Shallow clones mitigate cost, but very large histories may still impact performance
QA Checklist
- Connection test succeeds and shows project path and default branch
git --versionavailable on server; shallow clone succeeds- Push to target branch works with access token (Maintainer or higher if protected)
- Deploy subdirectory behavior:
- Delete Orphaned Files OFF: only additions/updates within
public/ - Delete Orphaned Files ON:
public/cleaned before copy; files outsidepublic/untouched
- Delete Orphaned Files OFF: only additions/updates within
- Commit author name/email reflect configured values
- Token is masked in logs and error messages
- No-op deploy logs “Nothing to commit” and push succeeds without error
- CI/CD pipeline triggers on commit and reads from
public/
Contributing
This add-on follows WP2Static's add-on architecture. Key files:
wp2static-addon-gitlab-private.php- Main plugin filesrc/GitLabPrivateDeployer.php- Core deployment logicviews/options-page.php- Admin interfaceuninstall.php- Cleanup script
Releases
2 releases. Each count is every asset in that release; expand a row for the breakdown.