gitlab ci rule 用法
时间: 2023-07-24 13:31:14 浏览: 90
gitlab使用教程
GitLab CI rules allow you to define when a job should be created and run based on a set of conditions. Here are a few examples of how to use GitLab CI rules in your pipeline:
1. Trigger a job based on changes in a specific file or directory:
```yaml
job:
script: echo "Hello, world!"
rules:
- changes:
- path/to/file
```
In this example, the job will be triggered only when there are changes in the `path/to/file` directory.
2. Trigger a job based on the creation of a new branch:
```yaml
job:
script: echo "Hello, world!"
rules:
- if: '$CI_COMMIT_BRANCH == "new-branch"'
```
In this example, the job will be triggered only when a new branch called `new-branch` is created.
3. Trigger a job based on the value of a specific variable:
```yaml
job:
script: echo "Hello, world!"
rules:
- if: '$ENVIRONMENT == "production"'
```
In this example, the job will be triggered only when the `ENVIRONMENT` environment variable is set to `production`.
4. Trigger a job based on a specific schedule:
```yaml
job:
script: echo "Hello, world!"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
```
In this example, the job will be triggered only when it is scheduled to run based on a specific time interval.
These are just a few examples of how to use GitLab CI rules in your pipeline. By using rules, you can create a highly customized and flexible pipeline that meets the specific needs of your project.
阅读全文