Gitlab Preview Deployment
Phase 1: Account Preparation
- Set a password for your Codesphere account (required for API access).
- Note: If you used Google/GitHub login, use the "Forgot Password" link to define a distinct password.
- Connect your GitLab account to Codesphere.
- Action: Click "+ New Workspace" and select "Connect GitLab" to authorize.
- Create a GitLab Project Access Token.
- Scopes: Select api.
- Role: Select Developer.
- Copy: Save this token immediately; you will need it for the secrets.
Phase 2: Configure GitLab Secrets
- Open your repository on GitLab.
- Navigate to Settings > CI/CD > Variables.
- Add the following variables (Uncheck "Protect variable" if your branch is not protected):
CODESPHERE_EMAIL: Your Codesphere login email.CODESPHERE_PASSWORD: Your Codesphere login password.CI_ACCESS_TOKEN: The Project Access Token created in Phase 1.
Phase 3: Configure Pipeline
- Create a
.gitlab-ci.ymlfile in your repository root. - Paste the following configuration:
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
stages:
- deploy
codesphere-deploy:
image: ghcr.io/codesphere-cloud/codesphere-monorepo/integrations/gitlab-ci:latest
stage: deploy
script:
- node /app/server.js
variables:
ACCESS_TOKEN: $CI_ACCESS_TOKEN
EMAIL: $CODESPHERE_EMAIL
PASSWORD: $CODESPHERE_PASSWORD
TEAM: 'My Team' # REPLACE with your exact Team Name
PLAN: 'Boost' # Options: Micro, Boost, Pro
ON_DEMAND: 'true' # 'true' enables cost-saving standby mode
ENV: | # Optional: Add environment variables below
MY_ENV=test
Phase 4: Deploy & Verify
- Commit and push the
.gitlab-ci.ymlfile. - Open a new Merge Request in your repository.
- Check the comment section of your Merge Request.
- Success: Codesphere will automatically post a comment with the direct link to your new Preview Deployment.