I had been looking for an online repository for a while.
Having code laying around in my computer, or in my laptop, or most recently on one of the clouds, is not very efficient.
If I can start doing Continuous Integration and Continuous Delivery (CI\CD) even better.
GitLab to the rescue!
GitLab is more than just a repository and more than just CI and CD.
Based on their website, GitLab can take care of your entire development cycle.
You can literally watch your code moving to every one of the development stages.
My goal is to be able to replace TFS (Team Foundation Server) and be able to upload my code to the repository, update code, build, test and eventually create docker images.
Of course, one step at the time.
In this article I am going to show you how to register for the FREE plan, and upload a Visual Studio Web Api code to the repository.
GitLab: Register to the Free Plan and Login
GitLab offers a free plan that is everything (and more) than I need.
You can choose to try the Enterprise (Paid) plan with all the bells and whistles free for 30 days, but for me, there was no reason to do that, knowing I don’t need the Enterprise features.
The best place to start is here: https://about.gitlab.com/pricing/
In this page, you can see every plan offered by GitLab, even some of the main features.
“Free – $0 per user / per month” sounds good to me.
Proceed by clicking the button to “Sign Up”.
On the next page, click on the “Register” tab and complete every field.
Complete the basic information: Full Name, Username, Email, Password. Accept the policies and click or solve the friendly “pain-in-the-neck” reCAPTCHA.
Click “Register”
You should receive an email to verify your email address and activate your account.
That’s it.
Now, let’s sign in.
Go to the sign in page or click here > https://gitlab.com/users/sign_in
On the first page you will be able to see all your PROJECTS, and should be empty now.
A project is the central location to store all your code (repository), from here you can create tickets and start CI\CD.
So, let’s add our first project.
Adding your First Project to GitLab
As you can see from the screen capture below, creating a project inside GitLab is very simple.
Enter your project name (hint: match the Visual Studio solution name).
After that, the Project slug is auto-filled.
Enter a description.
I decided to make my projects PRIVATE, but is your personal choice.
You can choose to “Initialize repository with a README” (very similar to GitHub). On a README file you can tell the world what your project does, why is useful, how to start (maybe installation steps for example), where to get help and information about the person in charge of maintaining this project.
So here is my new Project (I am using a basic web api code testing the OWIN Authentication token):
Click on “Create Project”
Voila!
Adding your Visual Studio Solution Code to GitLab
There are so many things to do and so many ways to do it… better!
But, I just wanted at this point to add my code to this new repository project.
We could also had chosen the push to the repository to create the project, but we will need to setup our SSH keys, which I haven’t yet at this point, but I will soon.
Let’s go step by step:
1. Open your PowerShell command window (Windows PowerShell Admin as I am running on a Windows 10 Pro).
2. CD all the way to the root folder of your solution. Calling a LS (to list the files under the directory) should return the main project folder, the packages folder and the .sln file.
3. Run the following commands:
>> git init >> git remote add origin https://gitlab.com/{your-username}/owin-authentication-web-api.git >> git add . >> git commit -m "Initial commit" >> git push -u origin master
4. And here is when the first error comes up:
error: open(".vs/OwinAuthenticationWebApi/v15/Server/sqlite3/db.lock"): Permission denied error: unable to index file .vs/OwinAuthenticationWebApi/v15/Server/sqlite3/db.lock fatal: adding files failed On branch master
Pretty simple stuff, let’s fix it.
How to Fix “Permission Denied” when Pushing Git Code
The main problem is the lack of a .gitignore file.
Files like the ones in the .vs folder and packages should be ignore.
There are a couple of easy solutions to this issue.
One, just create a text file named “.gitignore” on the same root folder as your .sln file, with the following patterns:
/.vs /packages
Or, if you have TortoiseGit installed (like I do), just open your File Explorer, right click on each of the folders and go to TortoiseGit > Add to ignore list > select the folder name.
That should also add the folder to the .gitignore local file.
Try the same commands to push the code to GitLab and now the result should be different:
To https://gitlab.com/{username}/owin-authentication-web-api.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'.
Go back to your GitLab project screen, and the repository should have all your files in the master branch.
GitLab: Next Steps
This was only the beginning.
Now that we have our code, we can setup another branch to update our code and create a CI/CD pipeline to build and deliver automatically.
My goal is to be able to create the pipeline and create a docker image.
As you can see from the screen below, the FREE EDITION of GITLAB includes this feature and more related to Docker:
And Kubernetes:
So the future is very interesting.
Thanks to GitLab of course, to have a wonderful application and allow for free use can only make the app better in the long run.
Before I go, here is a wonderful page full of GitLab documentation on just about everything: https://docs.gitlab.com/ee/README.html
Let’s add our SSH keys, create a pipeline and see if we can communicate natively with Visual Studio 2017.
If you like the article, please share it with your friends.