summaryrefslogtreecommitdiff
path: root/doc/builds_configuration/README.md
blob: 0afac2a680e01d8266a8a6464b35a2024c4dc6a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
## Configuration of your builds with .gitlab-ci.yml

From version 7.12, GitLab CI uses a .gitlab-ci.yml file for the configuration of your builds. It is placed in the root of your repository and contains three type of objects: before_script, builds and deploy_builds. Here is an example of how it looks:

```yaml
before_script: 
  - gem install bundler
  - bundle install 
  - bundle exec rake db:create

rspec: 
  script: "rake spec"
  tags: 
    - ruby
    - postgres
  only: 
    - branches

staging: 
  script: "cap deploy stating"
  type: deploy
  tags: 
    - capistrano
    - debian
  except:
    - stable
    - /^deploy-.*$/

```

Let's have a close look at each section.

### builds
Here you can specify parameters of your builds:

```yaml
rspec: 
  script: "rake spec"  # (required) - shell command for runner
  tags:                # (optional) - runner tags, only runners which have these tags will be used
    - ruby
    - postgres
  only:                # (optional) - git refs (branches and tags)
    - master

```

`rspec` is a key of this object and it determines the name of your build

`script` is a shell script which is used by runner. It will also be prepanded with `before_script`. This parameter can also contain several commands using array:

```yaml
script:
  - uname -a
  - bundle exec rspec
```

You can read about `only` and `except` parameters in the [refs settings explanation](#refs-settings-explanation)

### deploy_builds
Deploy Builds will be ran when all other builds have succeeded. Define them using simple syntax:

```yaml
production: 
  script: "cap deploy production" # (required) - shell command for runner
  type: deploy
  tags: 
    - ruby
    - postgres
  only:
    - master
```
`production` - is a name of deploy build

`script` - is a shell script which will be prepended with `before_script`

`type: deploy` is a parameter which indicates that it is a deploy job

You can read about `only` and `except` parameters in the [refs settings explanation](#refs-settings-explanation)

### before_script
`before_script` is used to define the command that should be ran before all builds, including deploy builds. This can be an array or a multiline string

### Refs settings explanation
There are two parameters that will help you set up the refs policy for your build or deploy build on CI
```
only:
  - master
```
`only` defines the exact name of the branch or the tag which will be ran. It also supports the regexp expressions:

```
only:
  - /^issue-.*$/
```
You can also use an `except` parameter:
```
except:
  - "deploy"
```
This parameter is used to exclude some refs. It is also supporting regexp expressions

There are also special keys like `branches` or `tags`. These parameters can be used to exclude all tags or branches
```
except:
  - branches
```

## Debugging your builds with .gitlab-ci.yml

Each instance of GitLab CI has an embeded debug tool Lint. You can find the link to the Lint in the project's settings page or use short url `/lint`

## Skipping builds
There is one more way to skip all builds, if your commit message contains tag [ci skip]. In this case, commit will be created but builds will be skipped