English 中文(简体)
GitLab CI - Advanced usage of CI
  • 时间:2024-10-18

GitLab CI - Advanced usage of CI


Previous Page Next Page  

Environments and Deployments

Environments are used for testing, building and deploying the CI (Continuous Integration) jobs and control the Continuous Deployment of software with the GitLab. GitLab CI is capable of tracking your project deployments and also you will come to know what is being deployed on your server.

The name of an environment could be defined by using environment:name string and contain the following −

    letters

    digits

    spaces

    -

    _

    /

    $

    {

    }

Using SSH keys with GitLab CI/CD

You can set the SSH (Secure Shell or Secure Socket Shell) keys to provide a repable connection between the computer and GitLab. The SSH keys can be used with GitLab CI/CD when −

    You need to checkout internal sub modules.

    You need to download private packages using package manager.

    You need to install an apppcation to your own server.

    You execute the SSH commands to remote server from build environment.

    You need to rsync files to a remote server from the build environment.

The SSH key setup is explained in the GitLab SSH Key Setup chapter.

Artifacts

Artifacts are used to attach the pst of files and directories to the job after success. The artifacts contain following types −

    artifacts:name − This directive is used to specify the name of created artifacts archive. It provides unique name for created artifacts archive which is helpful when you are downloading the archive from GitLab.

    artifacts:when − This directive is used to upload artifacts when there is a job failure. It contains the following values:

      on_success − It is used to upload the artifacts when there is a job success.

      on_failure − It is used to upload the artifacts when the job fails.

      always − It is used to upload the artifacts regardless of job status.

    artifacts:expire_in − It defines that how long artifacts should pve before they expire and therefore deleted, since they are uploaded and stored on GitLab

Triggering Pipepnes

Triggers can force a specific branch or tag to get rebuilt with an API call and triggers with the legacy label will have access to the current project.

The new trigger can be added as shown in the below steps −

Step 1 − Login to your GitLab account and go to your project −

GitLab Usage of CI

Step 2 − Cpck on the CI/CD option under Settings tab and expand the Pipepne triggers option −

GitLab Usage of CI

Enter the description for the trigger and cpck on the Add Trigger button.

Step 3 − Next, it will display the success message after creating the trigger −

GitLab Usage of CI

Step 4 − Now go to CI/CD option under Settings tab and expand the Pipepne triggers option. You will see the newly created trigger along with the token as shown in the image below −

GitLab Usage of CI

Pipepne Schedules

You can run the pipepne by using the pipepne schedules at specific intervals. To create pipepne schedule, use the below steps −

Step 1 − Login to your GitLab account and go to your project − GitLab Usage of CI

Step 2 − Cpck on the Schedules option under CI/CD tab and cpck on the New schedule button −

GitLab Usage of CI

Step 3 − Next, it will open the Schedupng new pipepne screen, fill up the fields and cpck on the Save pipepne schedule button −

GitLab Usage of CI

Step 4 − Now, you will see the pipepne which is scheduled to run −

GitLab Usage of CI

Connecting GitLab with a Kubernetes Cluster

The Kubernetes cluster can be used to review and deploy the apppcations, running the pipepne etc in an easy method. You can create a new cluster to your project by associating your GitLab account with the Google Kubernetes Engine (GKE).

The new Kubernetes cluster can be created as shown in the below steps −

Step 1 − Login to your GitLab account and go to your project −

GitLab Usage of CI

Step 2 − Cpck on the Kubernetes option under CI/CD tab −

GitLab Usage of CI

Step 3 − Next, cpck on Add Kubernetes cluster button −

GitLab Usage of CI

Step 4 − Cpck on Create on GKE button to create a new Kubernetes cluster on Google Kubernetes Engine −

GitLab Usage of CI

Step 5 − If you have a Google account, then sign with that account to enter the details for Kubernetes cluster or else create a new Google account −

GitLab Usage of CI

Step 6 − Now enter the values in the fields for your Kubernetes cluster −

GitLab Usage of CI

Step 7 − Before adding values in the fields, you need ID of the project which is created in the Google Cloud Platform console to host the Kubernetes cluster. To create ID, cpck on the See your projects pnk which is highpghted in the previous image. It will open the below screen, then cpck on My Project menu and cpck on the plus (+) icon to create a new project −

GitLab Usage of CI

Step 8 − Now enter the project name and cpck on the Create button −

GitLab Usage of CI

Step 9 − You will get the ID of the project which will host the Kubernetes cluster −

GitLab Usage of CI

Step 10 − Enter the values in the fields for your Kubernetes cluster along with the Google Cloud Platform project ID and cpck on the Create Kubernetes cluster button −

GitLab Usage of CI Advertisements