Bitnami Gitlab Deployment

What is Gitlab?

GitLab CE is an open-source, cloud-based Git repository and version control system. Its built-in CI/CD integrates with existing processes and helps teams deliver high-quality code and it is a single application for the entire DevOps lifecycle. This makes GitLab unique and makes Concurrent DevOps possible, unlocking your organization from the constraints of a pieced-together toolchain.

Why use the Bitnami Gitlab Stack?

The Bitnami Gitlab Stack is always up-to-date and secure. The installation and configuration of the stack is automated completely, making it easy for everyone, including those who are not very technical, to get them up and running.

Bitnami Gitlab CE Tutorials and documentation

Where To Find Gitlab Administration Panel credentials?

The instance/node/machine root credentials would be sent to your registered email address as soon as the Gitlab Instance is launched.

The credentials are stored in a standalone file. To obtain the credentials at any time, follow these steps:

Connect to the instance/node/machine through SSH using root user credentials.

Run the following command to obtain your application credentials:

cat /home/bitnami/bitnami_credentials

How do I access my Gitlab Administration Panel Using Browser ?

Once you have launched your Gitlab-CE instance, the IP address for your instance is sent to your account mail id. Access the Gitlab Administration Panel via your browser by entering this Public IP address.

http://$Public_IP

How to create a Continuous Integration(CI) Pipeline with GitLab and Jenkins?

Continuous Integration (CI) is an approach used for ensuring software quality through regular, automated builds. Within an hour, you can deploy a reliable, automated CI pipeline using open-source tools like GitLab and Jenkins. The following guide will help you with the setup.

Pre-requisites:

  • GitLab CE Stack and Jenkins Stack are launched or already running.

  • You have a standalone Git client or an IDE such as NetBeans or Eclipse with Git support.

  • The source code for your application is available with you.

  • For all these applications, IP addresses and administrative login credentials for all these applications are available.

  • Prepare two SSH key pairs (should be in OpenSSH format), one for communication between GitLab and Jenkins, and the other for communication between your local Git environment and GitLab.

Step 1: Create a GitLab project

The first step is to create a Git repository for your project source code using GitLab. This is where you and your team will push code changes, and this will also be the source repository for Jenkins’ automated builds. Follow these steps:

  • Create a new user account on GitLab and log in.

  • From the “Your Projects” tab, click the “New Project” button

  • On the “New Project” page, enter a name for the project and set the visibility level. The project in this example is set to “Public”, but you can also choose to make your project “Private” or “Internal”. Click “Create Project” once done.

NOTE: Read more about project visibility levels in the GiLab documentation.

GitLab will initialize an empty Git repository for the project, as shown below. Note the SSH URL to the repository, as you will need it in the next step.

Step 2: Configure SSH access to the GitLab project

Both Jenkins and your Git client will need access to the project repository, so this is a good time to configure that access. Follow these steps:

  • From the GitLab main menu (accessed via the hamburger icon in the top left corner), select the “Profile Settings” option.

  • Select the “SSH Keys” tab and enter the public key content (as a single line) for use between GitLab and your Git client. Add a descriptive title and click the “Add key” button to add it to your profile.

Repeat the steps above for the second key, to be used between GitLab and Jenkins. Once complete, you should see both public keys attached to your GitLab profile.

Step 3: Connect your project with the GitLab repository

Next, connect your project with the remote repository on GitLab and commit your initial code tree to it. You can do this from your IDE or via your Git tool.

If you’re using the Git command-line interface (CLI), follow these steps:

  • Ensure that your user account is configured to use the private SSH key defined for use with GitLab in Step 2.

  • Change into your project’s working directory and initialize a new local Git repository:

cd project
git init
  • Set the committer name and email address, replacing the NAME and EMAIL-ADDRESS placeholders below with actual values:

git config user.name "NAME"
git config user.email "EMAIL-ADDRESS"
  • Add the remote GitLab repository. Specify the repository name as origin and replace the SSH-URL-TO-GITLAB-REPOSITORY placeholder with the SSH URL to the repository (obtained in Step 1).

git remote add origin SSH-URL-TO-GITLAB-REPOSITORY
  • Add your project files to the local repository and commit them:

git add .
git commit -a
  • Push the changes to the remote repository:

git push origin master

Regardless of how you choose to commit your changes, if all goes well, you should see a success message and the committed files will appear in the Git repository on GitLab.

Step 4: Configure Jenkins

The next step is to connect Jenkins with GitLab, such that a new push to the GitLab repository automatically triggers a Jenkins build. This requires you to add the GitLab plugin to Jenkins and create SSH credentials so that Jenkins can access the GitLab project.

  • Log in to Jenkins and click the “Manage Jenkins” link.

  • Select the “Manage Plugins” option.

  • From the “Available” tab, find and select the GitLab plugin. Click the “Download now and install after restart” button to download it.

  • Once the plugin has been downloaded, click the “Restart Jenkins” checkbox and wait for Jenkins to restart.

If you want Jenkins to merge successful builds back to the GitLab repository, you also need to configure a Git user name and email address in Jenkins. To do this:

  • Click the “Manage Jenkins” link.

  • Select the “Configure System” option.

  • In the “Git plugin” section, enter a user name and email address.

  • Click “Save” to save the configuration.

Step 5: Create a Jenkins project

You’re now ready to create a Jenkins project and connect it to GitLab.

  • Log in to Jenkins and click the “New Item” link to create a new job.

  • Enter a name for the job and set it to be a “Freestyle project”.

  • On the job configuration page, find the “Source Code Management” section and select “Git”. - Configure the GitLab connection as follows:

  • Enter the SSH URL to the GitLab repository.

  • Click the “Add” button next to the “Credentials” field and select the “Jenkins” option.

  • In the resulting dialog, select “SSH Username with private key” as the credential type, set the “Username” to git, and enter the content of the private key selected for use between GitLab and Jenkins (remember that you already attached the corresponding public key to your GitLab profile in Step 2).

  • On the configuration page, select the newly-added credential and attach it to the SSH URL.

  • On the same configuration page, find the “Build Triggers” section and check the option to “Build when a change is pushed to GitLab”.

Note

the Jenkins service URL for the project next to the checkbox, as you will need this in the next step.

  • It is common to have Jenkins merge the new changes into the production branch before building. On the same configuration page, find the “Additional Behaviours” section and check the option to “Merge before build”. Specify the name of the repository as origin and the branch to merge to as production.

Note

The production branch does not exist yet. You will create it in the next step.

  • As part of the continuous integration process, you will also usually want Jenkins to automatically merge successful builds back into the production branch. To do this:

  • Click the “Add post-build action” button.

  • Select the “Git Publisher” option

  • Check the “Push only if build succeeds” and “Merge Results” options.

  • Specify the remote name and branch to push as origin and production respectively. You can also add custom tags if you wish.

Note

The production branch does not exist yet. You will create it in the next step.

  • Click “Save” to save the configuration.

Step 6: Create a GitLab branch for Jenkins

The Jenkins configuration in the previous step will merge successful builds to a production branch in the GitLab repository. This branch doesn’t exist yet so go ahead and create it, as follows:

  • Log in to GitLab and browse to the GitLab page for the project.

  • Select the “New branch” (accessed via the plus symbol) option.

  • Create a new branch named production derived from the existing master branch.

  • Click “Create branch” to create the new branch.

Step 7: Connect GitLab and Jenkins

The final step is to connect Jenkins and GitLab, such that Jenkins is automatically notified when there’s a new commit to the GitLab repository and can commit successful builds back to it. To do this:

  • Log in to GitLab and browse to the GitLab page for the project.

  • Open the project setting page (accessed via the cogwheel icon in the top right corner) and select the “Webhooks” option.

  • Configure a new Jenkins webhook as follows:

  • In the “URL” field, enter the Jenkins service URL from Step 5.

  • In the list of triggers, ensure that the “Push events” trigger is checked. Optionally, select other events that should trigger a new Jenkins build, such as new tags or new comments.

  • If you haven’t configured SSL, disable SSL by unchecking the “Enable SSL verification” flag.

  • Click “Add Webhook” to save the new settings.

You’re all set! To verify that it all works, head back to your project, make a change to your project source code and commit the changes. Then, push the changes to the GitLab repository as described in Step 3.

The push should automatically trigger a new build in Jenkins, with the build results visible on the Jenkins overview page for the project.

If the build is successful, Jenkins will also merge the build back to the production branch in the GitLab repository.

Your Continuous Integration (CI) pipeline is now ready for use!

Happy Coding!!