This repository demonstrates how to redeploy a Next.js application to Contentstack Launch using the Launch Public API file upload with GitLab CI. After the first deployment is done from the Launch UI or Launch APIs, the pipeline (.gitlab-ci.yml) runs on every push to main and redeploys the project using the script deploy-api.js.
The Launch API supports M2M, OAuth, or Authtoken. This example uses M2M (Client ID and Client Secret).
| Variable | Description |
|---|---|
CONTENTSTACK_CLIENT_ID |
M2M or OAuth application ID |
CONTENTSTACK_CLIENT_SECRET |
M2M or OAuth application secret |
CONTENTSTACK_REGION |
Region: AWS_NA, AWS_EU, AWS_AU, AZURE_NA, AZURE_EU, GCP_NA, GCP_EU |
PROJECT_UID |
Launch project UID |
ENVIRONMENT_UID |
Launch environment UID |
- First deployment: Perform the initial deployment from the Launch UI or Launch APIs. Create the project and deploy once.
- Subsequent deployments: Every push to
mainredeploys the project automatically through this GitLab CI pipeline.
- Perform the first deployment from the Launch UI or Launch APIs.
- Clone or copy this repository and push the code to a GitLab project.
- Create an application with
launch:manageorlaunch.projects:writescope (M2M is used in this example; OAuth and Authtoken are also supported by the API). - Add all required variables to GitLab CI/CD Variables or to
.envfor local runs. - Push to
mainto trigger a redeploy, or runnpm run deploylocally.
Running locally: Copy .env.example to .env, enter your values, then run npm run deploy.
Pipeline: The file .gitlab-ci.yml runs on push to main: it checks out the code, runs npm install form-data archiver dotenv, then runs node deploy-api.js.
Required variables (Settings → CI/CD → Variables): CONTENTSTACK_CLIENT_ID, CONTENTSTACK_CLIENT_SECRET, CONTENTSTACK_REGION, PROJECT_UID, ENVIRONMENT_UID.
The deploy script (deploy-api.js) includes in the zip only the files and folders listed in the essentialFiles array inside createZipFile(). The list is defined in code; there is no separate configuration file.
Default entries: package.json, package-lock.json, next.config.js, pages, public, app, functions
To customize: Edit deploy-api.js and update the essentialFiles array in createZipFile() to match your project (for example, add src, components, or lib; remove app or functions if not used). Only entries in that array are included in the zip.