Skip to content

Deploying with GitLab CI/CD

This guide explains how to set up a GitLab CI/CD pipeline that automatically triggers a new deployment on Seenode whenever a commit is pushed to a specified branch.

  • A GitLab repository containing your application.
  • An existing Seenode application linked to that repository.
  • An API token for the Seenode API.
  • Permissions to configure CI/CD settings in your GitLab project.
  1. Add CI/CD Variables to GitLab

    To keep your credentials secure, store them as masked and protected CI/CD variables in your GitLab project.

    1. In your GitLab project, go to Settings > CI/CD.
    2. Expand the Variables section.
    3. Click Add variable and add the following:
      • Key: SEENODE_APPLICATION_ID Value: The ID of your Seenode application.
      • Key: SEENODE_API_TOKEN Value: Your Seenode API token.
  2. Configure the GitLab CI/CD Pipeline

    Create a .gitlab-ci.yml file in the root of your repository to define your deployment pipeline.

    .gitlab-ci.yml
    stages:
    - deploy
    deploy_to_seenode:
    stage: deploy
    image: curlimages/curl:latest
    rules:
    - if: $CI_COMMIT_BRANCH == "main" # Trigger on pushes to the main branch
    script:
    - |
    curl -X POST \
    -H "Authorization: Bearer $SEENODE_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"gitCommitSha": "'"$CI_COMMIT_SHA"'"}' \
    "https://api.seenode.com/v1/applications/$SEENODE_APPLICATION_ID/deployments"

    This pipeline defines a deploy stage that runs a script to trigger a new deployment on Seenode. It uses a minimal curl image to execute the request. The job is configured to run only on pushes to the main branch.

  3. Commit and Push

    Commit the .gitlab-ci.yml file to your repository to activate the pipeline.

    Terminal
    git add .gitlab-ci.yml
    git commit -m "ci: Add GitLab CI/CD pipeline for Seenode deployment"
    git push
  4. Verify the Deployment

    Once you’ve pushed the pipeline configuration, you can verify that it’s working correctly.

    1. In your GitLab project, go to Build > Pipelines. You should see the pipeline running.
    2. In the Seenode Dashboard, navigate to your application’s Deployments tab. You should see a new deployment in progress.
  • Pipeline Not Triggering: Ensure you are pushing to the correct branch specified in the rules section of your .gitlab-ci.yml file.
  • Authentication Error: Double-check that your SEENODE_API_TOKEN and SEENODE_APPLICATION_ID variables are correct and that they are not configured to be protected if your branch is not a protected branch.
  • Command Not Found: The example uses an image with curl pre-installed. If you are using a different Docker image, ensure curl is available.
  • Invalid Request: Verify the API endpoint in the curl command. Ensure the application ID is correct.

You have now successfully set up a GitLab CI/CD pipeline to automatically deploy to seenode when changes are pushed to the repository. This automation ensures that your deployments stay consistent and efficient.