Commit f44def70 authored by Marcel Amirault's avatar Marcel Amirault

Merge branch 'selhorn-pages-exceptrule' into 'master'

Docs: Changed only and except to rules

Closes #219930

See merge request gitlab-org/gitlab!34332
parents 4bd80eee 682491a8
...@@ -169,12 +169,35 @@ The following topics show other examples of other options you can add to your CI ...@@ -169,12 +169,35 @@ The following topics show other examples of other options you can add to your CI
You may want to deploy to a Pages site only from specific branches. You may want to deploy to a Pages site only from specific branches.
You can add another line to `.gitlab-ci.yml`, which tells the Runner First, add a `workflow` section to force the pipeline to run only when changes are
to perform the job called `pages` on the `master` branch **only**: pushed to branches:
```yaml ```yaml
image: ruby:2.7 image: ruby:2.7
workflow:
rules:
- if: '$CI_COMMIT_BRANCH'
pages:
script:
- gem install bundler
- bundle install
- bundle exec jekyll build -d public
artifacts:
paths:
- public
```
Then configure the pipeline to run the job for the master branch only.
```yaml
image: ruby:2.7
workflow:
rules:
- if: '$CI_COMMIT_BRANCH'
pages: pages:
script: script:
- gem install bundler - gem install bundler
...@@ -183,8 +206,8 @@ pages: ...@@ -183,8 +206,8 @@ pages:
artifacts: artifacts:
paths: paths:
- public - public
only: rules:
- master - if: '$CI_COMMIT_BRANCH == "master"'
``` ```
## Specify a stage to deploy ## Specify a stage to deploy
...@@ -202,6 +225,10 @@ add a `stage` line to your CI file: ...@@ -202,6 +225,10 @@ add a `stage` line to your CI file:
```yaml ```yaml
image: ruby:2.7 image: ruby:2.7
workflow:
rules:
- if: '$CI_COMMIT_BRANCH'
pages: pages:
stage: deploy stage: deploy
script: script:
...@@ -211,16 +238,20 @@ pages: ...@@ -211,16 +238,20 @@ pages:
artifacts: artifacts:
paths: paths:
- public - public
only: rules:
- master - if: '$CI_COMMIT_BRANCH == "master"'
``` ```
Now add another job to the CI file, telling it to Now add another job to the CI file, telling it to
test every push to other branches, **except** the `master` branch: test every push to every branch **except** the `master` branch:
```yaml ```yaml
image: ruby:2.7 image: ruby:2.7
workflow:
rules:
- if: '$CI_COMMIT_BRANCH'
pages: pages:
stage: deploy stage: deploy
script: script:
...@@ -230,8 +261,8 @@ pages: ...@@ -230,8 +261,8 @@ pages:
artifacts: artifacts:
paths: paths:
- public - public
only: rules:
- master - if: '$CI_COMMIT_BRANCH == "master"'
test: test:
stage: test stage: test
...@@ -242,8 +273,8 @@ test: ...@@ -242,8 +273,8 @@ test:
artifacts: artifacts:
paths: paths:
- test - test
except: rules:
- master - if: '$CI_COMMIT_BRANCH != "master"'
``` ```
When the `test` job runs in the `test` stage, Jekyll When the `test` job runs in the `test` stage, Jekyll
...@@ -257,9 +288,8 @@ same time. ...@@ -257,9 +288,8 @@ same time.
## Remove duplicate commands ## Remove duplicate commands
To avoid running the same scripts for each job, you can add the To avoid duplicating the same scripts in every job, you can add them
parameter `before_script`. In this section, specify the commands to a `before_script` section.
you want to run for every job.
In the example, `gem install bundler` and `bundle install` were running In the example, `gem install bundler` and `bundle install` were running
for both jobs, `pages` and `test`. for both jobs, `pages` and `test`.
...@@ -269,6 +299,10 @@ Move these commands to a `before_script` section: ...@@ -269,6 +299,10 @@ Move these commands to a `before_script` section:
```yaml ```yaml
image: ruby:2.7 image: ruby:2.7
workflow:
rules:
- if: '$CI_COMMIT_BRANCH'
before_script: before_script:
- gem install bundler - gem install bundler
- bundle install - bundle install
...@@ -280,8 +314,8 @@ pages: ...@@ -280,8 +314,8 @@ pages:
artifacts: artifacts:
paths: paths:
- public - public
only: rules:
- master - if: '$CI_COMMIT_BRANCH == "master"'
test: test:
stage: test stage: test
...@@ -290,8 +324,8 @@ test: ...@@ -290,8 +324,8 @@ test:
artifacts: artifacts:
paths: paths:
- test - test
except: rules:
- master - if: '$CI_COMMIT_BRANCH != "master"'
``` ```
## Build faster with cached dependencies ## Build faster with cached dependencies
...@@ -305,6 +339,10 @@ when you run `bundle install`: ...@@ -305,6 +339,10 @@ when you run `bundle install`:
```yaml ```yaml
image: ruby:2.7 image: ruby:2.7
workflow:
rules:
- if: '$CI_COMMIT_BRANCH'
cache: cache:
paths: paths:
- vendor/ - vendor/
...@@ -320,8 +358,8 @@ pages: ...@@ -320,8 +358,8 @@ pages:
artifacts: artifacts:
paths: paths:
- public - public
only: rules:
- master - if: '$CI_COMMIT_BRANCH == "master"'
test: test:
stage: test stage: test
...@@ -330,11 +368,11 @@ test: ...@@ -330,11 +368,11 @@ test:
artifacts: artifacts:
paths: paths:
- test - test
except: rules:
- master - if: '$CI_COMMIT_BRANCH != "master"'
``` ```
In this case, we need to exclude the `/vendor` In this case, you need to exclude the `/vendor`
directory from the list of folders Jekyll builds. Otherwise, Jekyll directory from the list of folders Jekyll builds. Otherwise, Jekyll
will try to build the directory contents along with the site. will try to build the directory contents along with the site.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment