How can we start with Gitlab CI/CD? Part 02

Hello everyone, welcome to the wonderful part of the programming session on that where we had left the most important sections of GitLab CI/CD. Now, we are going to start from where we had left on the accounts of the creation of the .gitlab-ci.yml file or how to run the CI/CD pipeline. If you want to learn from scratch so, you may visit previously happened articles for proper assistance. So, let’s start with the rest part of the topic that describes most parts of the GitLab CI/CD.

Create .gitlab-ci.yml file

Step 1: Add .gitlab –ci.yml in the root folder of your projects/repo

I’m starting from where I had left the rest part of creating the GitLab YML file. So, after saving your project, you will go to your desktop and you will press command shift and dot on your keyword because this will be your hidden file you will copy that and move it to your projects folders you will have created a project and in the project folder, you had created a folder called GitLab in GitLab you had your first project. The same thing you can do in windows so the steps will remain the same you can just copy it in your projects folder wherever it is so it will be there your first projects you can just copy that file there so, you can actually copy that file there. Now, this was step number one and you will also copy the contents of that file so, you will see it you can also copy that in notes that will be the file you will have created this was step no. one and now, the step no. two is

Step 2: commit and push file to GitLab repository  

So, now because you have added that in your project you just need to commit and push in your gitlab repository you will have already know the commands for committing and pushing so, open your terminal there if you will on windows you can open git bash or the command line and first you will change the location to your project so, you will see say CD and go to your project folder and there if you say git status you will see you are getting that file will not yet added so you will say git add dot and all these comments you have learnt and then you will say git commit so if you again say git status you would see it in green so you will see now it will be added and then now you will say git commit –m “ added .gitlab-ci.yml file  and now you will push say git push –you origin/ master so you have you will give the URL instead of origin so there you will add the URL of your repository you will go to gitlab and go to your project and there you will click on clone and copy this HTTP link and provided there and hit enter if you will not have added your credentials there and you believe you have done it on windows you wil go to your command line and go to the location of your project there and now you will say git status and your file will be having there. You will say git add and git status again you will now say git commit –m “added .gitlab-ci .yml” and you would say git push –u origin master or you will say git push –u and give the link there of your first project they would push the changes if you go and check your project now you would have your GitLab CI ml file there so you will see now it will be there so you had pushed the changes.

Run CI/CD pipeline

 Now, the next thing is step no. three will be

Step 3: Create GitLab runner for the projects

So, if you go to your project you will go to your project go to settings and there you would go to CI/CD and in the runner, if you expand you will see you will have this runner created earlier so this runner will have already created so, this we have already done step no. three. Step no. four will also make sure that the runner that you are using has your tag that you will have given in your ml file so you will have your tag there CI that you will have given in your ml file now step four will be

Step 4: Start the runner  

Now, you will start the runner so, you will also start from your Mac or windows anywhere you will have learned this how to start so you will just say there brew service says start GitLab you don’t know if you will go to GitLab runner so, there is the documentation for GitLab runner so, you are on windows you will see there you will have for Mac for windows all these things you will have. And you can use this so if you are on windows you can just run this GitLab runner .exe start so there that will have already started so that is fine so you can start and stop but that is fine it will be started so once you can start that or now then step no. five will be

Step 5: Make any change in the project >> commit >> push

 So, basically what you will have done is you have added this CI job or you had added this GitLab CI YML file in your project that will now check for any commits and push in the project whenever you do any commits it will if you will have runner running if you will have GitLab runner running having the same tags like what you will have given in the file. For example: you will have given CI there then it will start the job whatever you will have given in the CI file in the gitlab CI file so now you will make some change there you will go there to your project and you will just some file there or you will not add a folder you will just add a file you will say new file you will say that is test 1.txt that will be test file and you will save and close it if you will go to your command line if you will say git status that will be added so you will say git add you can say test1.txt or you can say dot for everything and you will say git commit –m “added test1 .txt” and now you will have to push so you will say git push –u and the URL and master and once you do this when you will go to your projects there and you will go to CI/CD and once you will go there you will see this job’s getting triggered in the job section and you will push that if you will go there and refresh or you will go to the jobs you will see it is now there it will say pending so this is that will run now if you will go inside you will see that is a demo job one that you will have created in your gitlab CI file if you will click there you will see this is running and that will be now passed and you will see it is running hello World so it will say echo hello world and it will be printing hello world and you will see the locks there you will scroll from there that was a very small job so you don’t have lot of logs you can erase the job log you can see the complete raw log all that you can do so now on every commit and push in project it will check if you will have gitlab runner running and you will have this CI file the gitlab CI file it will run the file and whatever jobs you will have added whatever scripts you will have added it will run accordingly so from now on words whenever you will make changes it will triggers that jobs whatever you will have configured in your file so this is in very basic way how you can get started  with gitlab CI/CD of course there are lot of complex yml file set you can create as per your needsif you will go to the gitlab documentation you will see examples and samples of a lot of yml file and you can check them and see how you can use them so, this was the beginning of gitlab CI/CD at a very basic level so, I hope all this will very useful for you please do a hands-on and try some more jobs running some more jobs and gitlab CI/CD.