GitLab — Create a Simple Project and Run the Pipeline

Navya
4 min readDec 24, 2022

--

1. Create a Gitlab account https://gitlab.com/

2. Click a New project a Click “Create a blank project”

3. Enter the Project Name a Click the “Create project” button.

4. Build a pipeline.

5. In order to create a pipeline in GitLab CI we need to create a ‘New File’ that defines that pipeline.

6. Enter a File name and Select Template Type as ‘.gitlab-ci. yml’. YAML is a special format for the files that define those pipelines in GitLab and Apply a template as BASH.

7. We need to specify a ‘Job’. Job as the name suggests is a task that Gitlab should do for us.

a. Create a file and add a few texts to that file

build the car:
script:
- mkdir build // Create Directory
- cd build // Change Directory
- touch car.txt // Create a file
- echo "chasis" > car.txt // echo is used to display line of text/string
- echo "engine" > car.txt
- echo "wheels" > car.txt

b. Save the pipeline by ‘Clicking Commit changes’.

8. Go to Jobs and see the build.

Git Lab Runner:

The tool used by GitLab to run your jobs and send the results back to GitLab

We can use our own Runner or can use a shared Runner for our execution

Please refer :

Install the GitLab Runner: https://docs.gitlab.com/runner/install/

Register GitLab Runner: https://docs.gitlab.com/runner/register/

Define the Stages

1. After building the car we create the Test stage

a. Test the file was created the car.txt, The –f flag command is needed to check that the specified file exists.

b. Switch inside the build folder and check “chasis”, “engine”, and “wheels” using the grep command that helps for the search string.

c. We have to specify the order of stages needed to execute.

d. Save and commit changes.

e. Go to pipeline and see the stages. The build is successful but the Test is Failed with an error since the car.txt file not available in the build folder.

Defining the Artifacts

The Test failed because the jobs are running independently and do not exchange the data between the build and test stages. Thus, we need to define artifacts.

  1. Specify the path where the artifact is located.

2. Save the “build” folder, commit changes, and run the pipeline.

3. Test failed but executed the artifacts.

4. Go to the .yml and Append the build files using ‘the”>>” operator instead of overwriting the files.

The “>” Operator: “>” overwrites an already existing file or a new file is created providing the mentioned file name isn’t there in the directory.

The “>>” Operator: “>>” operator appends an already present file or creates a new file if that file name doesn’t exist in the directory.

5. We can add commands like ls and cat to show the contents in the Test stage.

6. Commit, Run the pipeline, and Check the results.

Save the artifacts:

The artifacts are independent that’s why we are not able to see the “build” folder inside the project.

Go to Pipeline → Download the artifacts

--

--

Navya

Motivator l Software Engineer I Movie freak l Enthuiastic Learner | Blogger