Skip to main content

Using GitLab CI/CD

GitLab CI/CD is a continuous integration and continuous deployment service integrated into GitLab repositories. It automates the processes of building, testing, and deploying software, streamlining software development workflows.

This guide shows how to integrate Continuous Delivery with Git in Appsmith, enabling automatic updates to the master branch with GitLab CI/CD. This eliminates the need for manual pulling after each update.

Prerequisites

Configure continuous delivery

Follow these steps to configure GitLab CI/CD workflow and automate continuous delivery for your Appsmith application:

  1. In GitLab, go to Build tab and select Pipelines.

  2. Select one of the available templates. If you're unsure, use the test template.

  3. Configure the YAML file. Alternatively, you can directly create a file named gitlab-ci.yml within your project directory. GitLab requires the filename to be exactly as gitlab-ci.yml.

This YAML code configures a GitLab Pipeline to execute a deployment task using the curl command provided by Appsmith.

stages:
- deploy

deploy-job:
stage: deploy
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- when: never
script:
# - echo $APPSMITH_CD
- "curl --location --fail-early --request POST https://app.appsmith.com/api/v1/git/deploy/app/66042fd670bf652918?branchName=master --header \"Authorization: Bearer $APPSMITH_CD\""
  1. Open your Appsmith application and then select Git Settings located on the left side of the bottom bar.

  2. Click on the Continuous Delivery tab.

  3. Select the branch where you want to implement continuous delivery. For example, the master branch or any feature branch.

  4. Copy the Appsmith-provided endpoint and paste it into your CI/CD pipeline configuration. Replace the curl command with the command provided by Appsmith(as mentioned in the YAML file in step 3).

  5. Generate and copy the bearer token for authenticating requests to the provided endpoint. Save this token for future reference. Once done, click the Finish Setup button in your Appsmith application.

  6. In GitLab, add the bearer token. It is recommended that you create secrets or secure variables instead of directly adding them to the repository.

Example: You can use GitLab's variables and secrets to securely store your bearer token. Add your token as a variable within the CI/CD settings of your repository. Subsequently, in your YAML file, use the token using $GITLAB_CD_TOKEN, like:

Replace:
- 'Authorization: Bearer <bearer token>'
With:
- "Authorization: Bearer $GITLAB_CD_TOKEN\"

For information see GitLab CI/CD variables.

  1. Commit the YAML file changes to the repository.

  2. To check the status, open the Pipelines tab:

Image
Pipeline Status

Upon successful completion of the run, you can monitor the pipeline's status, access detailed log information from its execution, and gather various other data. For information see GitLab CI/CD pipelines.

Test the continuous delivery

Follow these steps to test continuous delivery after you have committed the YAML workflow file and added the bearer token:

  1. Open the Appsmith App and create a new feature branch.

  2. Commit & Push your modifications to the designated feature branch.

  3. Open the repository and raise a pull request.

  4. When you merge this into the master or specified branch, the pipeline workflow automatically triggers and updates the deployed version and branch accordingly.

The changes are deployed to that branch without the need to pull the changes manually. Additionally, the live version of the Appsmith app reflects those changes.