https://docs.gitlab.com/ee/ci/introduction/
.gitlab-ci.yml
normally.You need a GitLab Runner first.
Please refer my GitLab Runner install post :)
.gitlab-ci.yml
- your own GitLab instanceOfficial tutorial: https://docs.gitlab.com/ee/ci/quick_start/
my_job_1
in the following example)..gitlab-ci.yml
my_job_1:
tags:
- runner1
script:
- echo "What a nice day!"
my_job_2:
tags:
- runner1
script:
- echo "Tommorow would be better than today."
.gitlab-ci.yml
- public GitLabIf you want to use public GitLab CI/CD runner, omit tags
fields.
As of April 2022, you need a credit card information to reduce an abuse of public GitLab CI/CD.
Go Your Project -> CI/CD
my_job_1
and my_job_2
.Running with gitlab-runner 13.9.0 (2ebc4dc4)
on A shared GitLab Runner for {{ my_GitLab_domain}} xy-ABCDE
Preparing the "docker" executor
00:05
Using Docker executor with image alpine:3.13 ...
Pulling docker image alpine:3.13 ...
Using docker image sha256:28f6e27057430ed2a40dbdd50d2736a3f0a295924016e294938110eeb8439818 for alpine:3.13 with digest alpine@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be ...
Preparing environment
00:01
Running on runner-xy-abcde-project-5-concurrent-0 via {{ my_GitLab_Runner_domain}}...
Getting source from Git repository
00:00
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/{{ my_GitLab_username }}/{{ my_repository_name }}/.git/
Created fresh repository.
Checking out 0520e589 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
Using docker image sha256:28f6e27057430ed2a40dbdd50d2736a3f0a295924016e294938110eeb8439818 for alpine:3.13 with digest alpine@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be ...
$ echo "What a nice day!"
What a nice day!
Cleaning up file based variables
00:00
Job succeeded
We can define “stage"s also.
Note that the default value of stage is test
.
Let’s focus on single job, and configure more details. You can find the whole list of keywords at here.
default:
image: rust:1.60-alpine3.15
job_1:
stage:
script:
- echo "What a nice day!"
- cargo --version
stages:
- my_build
- my_test
- my_deploy
job1:
stage: my_build
script:
- echo "This job compiles code."
job2:
stage: my_test
script:
- echo "This job tests the compiled code. It runs when the build stage completes."
job3:
stage: my_test
script:
- echo "This job also runs in the test stage".
job4:
stage: my_deploy
script:
- echo "This job deploys the code. It runs when the test stage completes."
stages
list also decides order of stages.stage
, runner try to run in parallel.variables:
DEPLOY_SITE: "https://atlex00.com/"
my_build_job:
stage: build
script:
- echo $DEPLOY_SITE
my_deploy_job:
stage: deploy
variables:
SPECIAL_PATH: "/review"
script:
- echo SPECIAL_PATH is $SPECIAL_PATH
https://docs.gitlab.com/ee/ci/jobs/#hide-jobs
#
is normal way, or, append a dot .
can also comment out the job.
rules
: https://docs.gitlab.com/ee/ci/yaml/index.html#rules
https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html
.my_job: &my_job
and <<: *my_job
.
Anchors YAML has a feature called ‘anchors’ that you can use to duplicate content across your document.
Use anchors to duplicate or inherit properties. Use anchors with hidden jobs to provide templates for your jobs. When there are duplicate keys, GitLab performs a reverse deep merge based on the keys.
Here is a sample Ansible playbook.
---
- name: Test Playbook
gather_facts: false
hosts: your-own-host.com
tasks:
- name: Echo in Ansible
shell:
cmd: echo "I'm in a playbook!"