Home  > Resources  > Blog

Create a Project in GitLab

 
December 30, 2022 by Bibhas Bhattacharya
Category: DevOps

This tutorial is adapted from the Web Age course https://www.webagesolutions.com/courses/WA3243-advanced-gitlab-administration.

A Git repository is called a project in GitLab. That is because a project is much more than a file repository. You can also define the CI/CD pipeline for the application in a project.
In this tutorial, we will create a new project. We will push the application code to it.
Our application is a very simple Java web service. You can send it a request like this:

curl http://localhost:8080/hello

It will respond back with a JSON.

{"requestCount":1,"greeting":"Hello!"}

Part 1 – Sign into GitLab

A local instance of GitLab is configured in your machine. We will make sure that it is
running and we can log into it.
1. Open a terminal.
2. Run this command to verify the gitlab Docker container is running:

docker ps

Troubleshooting
If gitlab is not running then start it as follows:

docker start gitlab

It can take about 10 minutes for it to start.
3. Open FireFox and enter the URL:

http://localhost

4. Log in using the following credentials:

User name: root
Password: gitlabadmin

Part 2 – Setup Git

1. In the Terminal, enter these commands to setup your Git user name and email:

git config --global user.email "bob@example.com"
git config --global user.name "Bob Developer"

Part 3 – Create Users

We will now create two users:

  1. An admin user. This user will own the project.
  2. A developer user. This user will be able to push and pull code using the project.
  1. In the browser, click the hamburger icon to expose the menu and then click Admin.

2. Click Users.

  1. Click New user.
  2. Enter these values:
Name: Bob Developer
Username: bobdeveloper
Email: bob@example.com
  1. Click Create user.
  2. Click Edit.

7. Set the password to bobdeveloper
8. Click Save changes.

9. Similarly create a user with these specs:

Name: Alice Admin
User name: aliceadmin
Email: alice@example.com
Password: aliceadmin

10. Click Users. You should see:

11. Log out of GitLab.

Part 4 – Activate Account

Normally, bobdeveloper and aliceadmin will receive an invitation email. They can use the
link there to activate their accounts. We don’t have email setup. So we will manually
activate the accounts.

  1. Log in as bobdeveloper (password bobdeveloper).

2. Re-enter the same password (bobdeveloper) and click Set new password to save
changes.

3. Repeat the process for aliceadmin (password aliceadmin).

Part 5 – Create the Project

  1. Log into GitLab as aliceadmin (password is also aliceadmin).
  2. Click Create a Project.

3. Click Create blank project.
4. Enter gitops-demo-webapp as the Project name.

5. Uncheck Initialize repository with a README.

6. Click Create project.

Part 6 – Give Developer Access to the Project

  1. On the left menu, click Project information.
  1. Click Members.
  2. Click Invite members.
  3. Search for bob and select Bob Developer.

5. Select Developer as the role.

6. Click Invite.
Bob now has a developer level access to this project.

Part 7 – Inspect the Application Code


The application code is given to you in ~/LabFiles/gitops-demo-webapp.

The application code is given to you in ~/LabFiles/gitops-demo-webapp. Feel free to
inspect the files there. As an administrator you don’t need to know too much about the
code.


Part 8 – Add Application Code to GitLab

We will now move the application code to GitLab.
1. In the browser, download the following file:

https://webage-downloads.s3.amazonaws.com/Supporting/WA3243-REL_1_0-Supporting.zip

2. Open a File browser and navigate to ~Downloads. The file that just downloaded
should be there, if it is not there find the folder where was saved.
3. Right click the file and select Extract here.
4. The folder WA3243-REL_1_0-Supporting will be created, open it.

5. Drag and drop the LabFiles folder to Home.

6. Open Home and make sure the LabFiles folder is shown.
7. Open a terminal.
8. Go inside the application code folder:

cd ~/LabFiles/gitops-demo-webapp

9. Initialize git:

git init

10. Commit the code:

git add .
git commit -m"Initial commit"

11. Add our GitLab server as the remote origin:

git remote add origin http://localhost/aliceadmin/gitops-demowebapp.git

12. Finally, push the code:

git push --set-upstream origin master

13. Log in as aliceadmin for username and password:

14. In the GitLab web site go to the project’s page:

http://localhost/aliceadmin/gitops-demo-webapp

Make sure you see the code:

Part 9 – Review

In this tutorial, you did the following:

  1. Create a few users.
  2. Create a new project as aliceadmin. She will be the project’s owner.
  3. Pushed code to the GitLab project.

Follow Us

Blog Categories