GitLab CI/CD: “Hello World” – Example

GitLab CI/CD is a part of GitLab that is used for continuous integration (CI), delivery (CD) and deployment (CD).

With GitLab CI/CD, you can automatically build, test and publish your software with no third-party application or integration needed.

In this note i am showing an example of how to create a new repository in GitLab with a “Hello World” CI/CD pipeline that will be triggered automatically on each commit and push to remote.

Cool Tip: Print all environment variables in GitLab CI/CD! Read more →

GitLab CI/CD: “Hello World” Example

Create a new gitlab-ci-cd-hello-world Git repository, push it to GitLab and set up a remote origin (replace <username> in the URLs with your username):

$ mkdir gitlab-ci-cd-hello-world
$ cd gitlab-ci-cd-hello-world
$ git init
$ touch .gitignore
$ git add -A
$ git commit -m 'Initial commit'
# for Git over HTTPS
$ git push --set-upstream<username>/gitlab-ci-cd-hello-world.git
$ git remote add origin<username>/gitlab-ci-cd-hello-world.git
# for Git over SSH
$ git push --set-upstream<username>/gitlab-ci-cd-hello-world.git
$ git remote add origin<username>/gitlab-ci-cd-hello-world.git

Create GitLab CI/CD “Hello World” Pipeline

GitLab CI/CD pipelines are configured using a YAML file called .gitlab-ci.yml.

Create the .gitlab-ci.yml file at the root of your repository with the contents as follows:

# .gitlab-ci.yml

# The names and order of the pipeline stages
  - build
  - test
  - deploy

  stage: build
    - echo "Building the 'Hello World' app"

  stage: test
    - echo "Testing the 'Hello World' app"

  stage: deploy
    - echo "Deploying the 'Hello World' app"

Commit and push to GitLab:

$ git add -A
$ git commit -m 'Create CI/CD pipeline'
$ git push origin

The created pipeline will be executed automatically once pushed to remote.

To see the running pipeline – go to your project’s CI/CDPipelines on GitLab’s UI or simply open this URL in your web-browser (replace <username> with your username):<username>/gitlab-ci-cd-hello-world/-/pipelines

Cool Tip: Save username & password in Git credentials store! Read more →

Leave a Reply