How to Connect GitLab Self-Managed with AWS CodePipeline

Varun Kumar Manik
5 min readJul 6, 2024

--

Introduction

AWS CodePipeline is a powerful CI/CD service that allows you to automate your release processes. Integrating GitLab self-managed with AWS CodePipeline provides a seamless way to automate builds, tests, and deployments. This guide will walk you through the steps to connect your self-managed GitLab instance with AWS CodePipeline and deploy the output to an S3 bucket.

Prerequisites

Step 1: Create a Personal Access Token in GitLab

  1. Log in to your GitLab instance.
  2. Navigate to User Settings:
  • Click on your profile picture in the top-right corner and select “Settings”.
  1. Create a Personal Access Token:
  • Go to “Access Tokens” under the “User Settings” menu.
  • Provide a name for the token, set an expiration date, and select the api scope.
  • Click “Create personal access token”.
  • Save the generated token securely as you will need it later.

Step 2: Create a Connection to GitLab Self-Managed in AWS CodePipeline Console

  1. Sign in to the AWS Management Console and open the CodePipeline service.
  2. Create or Edit a Pipeline:
  • To create a pipeline, follow the steps in “Create a Pipeline” and complete the first screen. On the Source page, under Source provider, choose GitLab self-managed.
  • To edit an existing pipeline, choose “Edit” and then “Edit stage”. Add or edit your source action. On the Edit action page, under Action name, enter a name for your action and choose GitLab self-managed as the Action provider.

Step 3: Create a Connection to GitLab Self-Managed

  1. Under Connection, choose “Connect to GitLab self-managed”.
  1. Create a Connection:
  • Follow the steps to create a connection.
  • Enter the following details:
  • Connection name: Choose a name for the connection.
  • GitLab server URL: Enter the URL of your GitLab instance.
  • Personal access token: Enter the personal access token you created in GitLab.
  • Click “Connect”.

Detailed Steps on GitLab Connectivity

  1. GitLab Server URL:
  • Ensure that your GitLab instance is accessible from the internet or the VPC where AWS services can reach it. Use the fully qualified domain name (FQDN) for the GitLab server URL.
  1. Creating the Personal Access Token:
  • Go to your GitLab instance and navigate to your user settings.
  • Under Access Tokens, create a new token with the required scopes (api).
  • This token will be used by AWS to authenticate and access your GitLab repositories.
  1. Configuring the Connection:
  • In AWS CodePipeline, when you select “Connect to GitLab self-managed,” you will be prompted to enter the GitLab server URL and the personal access token.
  • AWS will use this connection to poll for changes in your GitLab repository and trigger the pipeline accordingly.

Step 4: Set Up AWS CodePipeline

  1. Create a New Pipeline:
  • In the AWS Management Console, navigate to CodePipeline and click “Create pipeline”.
  • Provide a name for your pipeline and click “Next”.
  1. Set Up the Source Stage:
  • Choose “GitLab self-managed” as the source provider.
  • Select the connection you created earlier.
  • Enter the repository name and branch name.
  1. Set Up the Build Stage:
  • Choose “AWS CodeBuild” as the build provider.
  • Configure a build project or create a new one.
  • Set the environment and build commands according to your project requirements.

Step 5: Set Up the Deploy Stage to S3

  1. Create an S3 Bucket:
  • In the AWS Management Console, navigate to the S3 service.
  • Create a new S3 bucket where you will deploy your build artifacts.
  1. Configure the Deploy Stage:
  • In your CodePipeline, add a deploy stage.
  • Choose “Amazon S3” as the deploy provider.
  • Select the S3 bucket you created.
  • Specify the S3 object key (e.g., my-app/) where your build artifacts will be stored.

Step 6: Verify the Integration

  1. Trigger a Build:
  • Make a change to your GitLab repository and push it to the specified branch.
  1. Monitor the Pipeline:
  • Go to the AWS CodePipeline console to monitor the progress of your pipeline.
  • Ensure that the source, build, and deploy stages are working as expected.

Testing the Connection:

  • After setting up the connection, it is a good practice to test it by pushing a change to the GitLab repository and checking if the pipeline triggers as expected.

Conclusion

By following these steps, you have successfully connected your self-managed GitLab instance with AWS CodePipeline and configured it to deploy build artifacts to an S3 bucket. This integration allows you to automate your CI/CD workflows and streamline your software release process. Enjoy the power of continuous integration and delivery with GitLab and AWS CodePipeline!

--

--

Varun Kumar Manik
Varun Kumar Manik

Written by Varun Kumar Manik

AWS APN Ambassador | SME of DevOps DevSecOps | Cloud Architect & Trainer | Blogger | Youtuber |Chef

No responses yet