Git & Gitlab - Cheatsheet
Git & Gitlab - Cheatsheet
Git Commands
GitLab-Specific Commands
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building the project."
test_job:
stage: test
script:
- echo "Running tests."
deploy_job:
stage: deploy
script:
- echo "Deploying application."
● Defining Artifacts:
artifacts:
paths:
- build/
only:
- master
● Cache Dependencies:
cache:
paths:
- .maven/
image: maven:latest
● Defining Variables:
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml"
services:
- postgres:latest
deploy_prod:
stage: deploy
script:
- echo "Deploying to production."
when: manual
● Scheduled Pipelines:
○ Configured through the GitLab UI under CI/CD > Schedules.
Advanced CI/CD
● Multi-Project Pipelines:
○ Use trigger in .gitlab-ci.yml to trigger pipelines in other
projects.
● Environment and Deployment:
deploy_to_prod:
stage: deploy
environment:
name: production
script:
- echo "Deploying to production."
Review Apps:
include:
- project: 'other/project'
ref: master
file: '/path/to/template.yml'
.template: &template
script:
- echo "This is a script template."
deploy_staging:
stage: deploy
script: echo "Deploying to staging"
environment: staging
build:
stage: build
script: make build
artifacts:
paths:
- build/
test:
stage: test
script: make test
dependencies:
- build
image: docker:19.03.12
services:
- docker:19.03.12-dind
trigger:
project: my/other-project
branch: master
variables:
DATABASE_URL: "postgres://..."
cache:
paths:
- .maven/
build:
stage: build
trigger:
include: 'path/to/child-pipeline.yml'
job1:
tags:
- linux
- docker