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 README.md $ git add -A $ git commit -m 'Initial commit' # for Git over HTTPS $ git push --set-upstream https://gitlab.com/<username>/gitlab-ci-cd-hello-world.git $ git remote add origin https://gitlab.com/<username>/gitlab-ci-cd-hello-world.git # for Git over SSH $ git push --set-upstream git@gitlab.com/<username>/gitlab-ci-cd-hello-world.git $ git remote add origin git@gitlab.com/<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 stages: - build - test - deploy build-job-example: stage: build script: - echo "Building the 'Hello World' app" test-job-example: stage: test script: - echo "Testing the 'Hello World' app" deploy-job-example: stage: deploy script: - 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/CD
→ Pipelines
on GitLab’s UI or simply open this URL in your web-browser (replace <username> with your username):
https://gitlab.com/<username>/gitlab-ci-cd-hello-world/-/pipelines
Cool Tip: Save username & password in Git credentials store! Read more →