After reading this section, you will learn:
YAML
The basic grammar of the language;.gitlab-ci.yml
Configuration file details;Gitlab-CI
Configuration operations.
YAML
The YAML language (pronounced /ˈjæməl/) was designed to make it easy for humans to read and write configuration files. It is essentially a universal data serialization format.
Its basic syntax rules are as follows:
- Case sensitivity
- Use indentation to indicate hierarchy
- Indentation is not allowed
Tab
Key. Only Spaces are allowed - The number of Spaces indented does not matter, as long as elements of the same rank are aligned to the left
# indicates a comment, which is ignored by the parser all the way to the end of the line.
YAML supports three types of data structures:
- Object: A collection of key-value pairs, also called a map (
mapping
)/hash (hashes
)/Dictionary (dictionary
) - 1. An ordered set of values, also called a sequence (
sequence
)/List (list
) - Scalar (
scalars
) : single, non-divisible value
Another small quirk of YAML is that all YAML files should start at the beginning, which is part of the YAML format.
object
An object is a set of key-value pairs, denoted by a colon:
---
animal: pets
Copy the code
Convert to JavaScript as follows:
{ animal: 'pets' }
Copy the code
YAML also allows another way of writing, which pairs all the keys to a ctrip in-line object:
---
hash: { name: Steve.foo: bar }
Copy the code
Convert to JavaScript as follows:
{ hash: { name: 'Steve'.foo: 'bar'}}Copy the code
An array of
A set of lines at the beginning of a conjunction line, forming an array:
---
- Cat
- Dog
- Goldfish
Copy the code
Convert to JavaScript as follows:
[ 'Cat'.'Dog'.'Goldfish' ]
Copy the code
If the child member of the data structure is an array, space can be indented below the item:
---
-
- Cat
- Dog
- Goldfish
Copy the code
Convert to JavaScript as follows:
[['Cat'.'Dog'.'Goldfish']]Copy the code
YAML arrays can also use inline notation:
---
animal: [ Cat.Dog ]
Copy the code
Convert to JavaScript as follows:
{ animal: [ 'Cat'.'Dog']}Copy the code
Composite structure
Objects and arrays can be used together to form compound structures:
---
languages:
- Ruby
- Perl
- Python
websites:
`YAML`: yaml.org
Ruby: ruby-lang.org
Python: python.org
Perl: use.perl.org
Copy the code
Convert to JavaScript as follows:
{
languages: ['Ruby'.'Perl'.'Python'].wesites: {
`YAML`: 'yaml.org'.Ruby: 'ruby-lang.org'.Python: 'python.org'.Perl: 'use.perl.org',}}Copy the code
scalar
A scalar is a fundamental, nonseparable value. The following data types are JavaScript primitives:
- string
- Boolean value
- The integer
- Floating point Numbers
Null
- time
- The date of
Values are expressed directly as literals:
number: 12.35
Copy the code
Convert to JavaScript as follows:
{ number: 12.30 }
Copy the code
Boolean values are true and false:
isSet: true
Copy the code
Convert to JavaScript as follows:
{ isSet: true }
Copy the code
Null is represented by ~ :
parent: ~
Copy the code
Convert to JavaScript as follows:
{ parent: null }
Copy the code
Time in ISO8601 format:
iso8601: The 2001-12-14 t21:59:43. 10 to 05:00
Copy the code
Convert to JavaScript as follows:
{ iso8601: new Date('the 2001-12-14 t21:59:43. 10-05:00')}Copy the code
The date is expressed as year, month and day in composite ISO8601 format:
date: 1976-07-31
Copy the code
Convert to JavaScript as follows:
{ date: new Date('1976-07-31')}Copy the code
YAML allows two exclamation marks to cast data types:
port: !!!!! str 8000
year: !!!!! int '1991'
success: !!!!! bool 'true'
distance: !!!!! float '18.32'
Copy the code
Convert to JavaScript as follows:
{
port: '8000'.year: 1991.success: true.distance: 18.32,}Copy the code
string
Strings are the most common and complex type of data.
Strings are not quoted by default:
str: This is a string
Copy the code
Convert to JavaScript as follows:
{ str: 'This is a string.' }
Copy the code
If the string contains Spaces or special characters, it needs to be enclosed in quotes:
str: 'Content string'
Copy the code
Convert to JavaScript as follows:
{ str: 'Content string' }
Copy the code
Both single and double quotation marks can be used, and double quotation marks do not escape special characters:
str1: 'Content \n string'
str2: "Contents \n string"
Copy the code
Convert to JavaScript as follows:
` ` ` ` JavaScript ` {str1: ‘\ n content string, str2:’ content \ n string ‘}
'' yaml STR: 'labor'' day'Copy the code
Convert to JavaScript as follows:
{ str: 'labor\'s day' }
Copy the code
Strings can be written as multiple lines, starting with the second line, which must have a single space indent, and the newline character is converted to a space:
str: This is a paragraph
Multiple lines
string
Copy the code
Convert to JavaScript as follows:
{ str: 'This is a multi-line string.' }
Copy the code
Multi-line string can use | retain a newline, can also use > fold line:
this: | Foo Barthat: > Foo BarCopy the code
Convert to JavaScript as follows:
{ this: 'Foo\nBar\n'.that: 'Foo Bar\n' }
Copy the code
+ preserves the end of the text block and – removes the end of the string:
s1: | Foo
s2: |+ Foo
s3: |- FooCopy the code
Convert to JavaScript as follows:
{ s1: 'Foo\n'.s2: 'Foo\n\n\n'.s3: 'Foo' }
Copy the code
HTML tags can be inserted into strings:
message: | < p style = "color: red" > paragraph < / p >Copy the code
Convert to JavaScript as follows:
{ message: '\n\n paragraph \n
\n' }
Copy the code
reference
Anchors & and aliases * can be used to indicate references:
defaults: &defalts
adapter: postgres
host: localhost
development:
database: myapp_development
< < : *defaults
test:
database: myapp_test
< < : *defaults
Copy the code
Equivalent to the following code:
defaults:
adapter: postgres
host: localhost
development:
database: myapp_development
adapter: postgres
host: localhost
test:
database: myapp_test
adapter: postgres
host: localhost
Copy the code
& is used to create anchor points, << means to merge into current data, and * refers to anchor points:
- &showell Steve
- Clark
- Brian
- Oren
- *showell
Copy the code
Convert to JavaScript as follows:
[ 'Steve'.'Clark'.'Brian'.'Oren'.'Steve' ]
Copy the code
.gitlab-ci.yml
GitLab provides continuous integration services. If you add the.gitlab-ci.yml file to the root of your project and configure the Gitlab repository to use Runner, gitlab will look for the.gitlab-ci.yml file and start operations on Runner based on its contents every time you commit or push.
The resources
YAML language tutorial
www.ruanyifeng.com/blog/2016/0…
2. Keyword reference for the .gitlab-ci.yml
file
docs.gitlab.com/ee/ci/yaml/