GitLab CI语法[only|except|rules|workflow]
定义哪些分支和标签的git项目将会被job执行。
except
job:
# use regexp
only:
- /^issue-.*$/
# use special keyword
except:
- branches
允许按顺序评估单个规则对象的列表,直到一个匹配并为作业动态提供属性. 请注意, rules
不能only/except
与only/except
组合使用。
- if
- changes (only:changes相同)
- exists
DOMAIN
的值匹配,则需要手动运行。不匹配on_success
。 条件判断从上到下,匹配即停止。多条件匹配可以使用
variables:
DOMAIN: example.com
codescan:
stage: codescan
tags:
- build
script:
- echo "codescan"
- sleep 5;
#parallel: 5
rules:
- if: '$DOMAIN == "example.com"'
when: manual ##如果条件成立执行这个
- when: on_success ##如果条件不成立执行这个
Jenkinsfile
codescan:
stage: codescan
tags:
- build
script:
- echo "codescan"
- sleep 5;
#parallel: 5
rules:
- changes:
- Jenkinsfile
when: manual
allow_failure: true
- if: '$DOMAIN == "example.com"'
when: on_success
- when: on_success
接受文件路径数组。当仓库中存在指定的文件时操作。
codescan:
stage: codescan
tags:
- build
script:
- echo "codescan"
- sleep 5;
#parallel: 5
rules:
- exists:
- Jenkinsfile
when: manual
- changes:
- Jenkinsfile
when: on_success
- if: '$DOMAIN == "example.com"'
when: on_success
- when: on_success
allow_failure: true
rules:
job: script: "echo Hello, Rules!" rules: - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' when: manual allow_failure: true
when: manual
和allow_failure: true
workflow:
关键字适用于整个管道,并将确定是否创建管道。when
:可以设置为always
或never
. 如果未提供,则默认值always
variables:
DOMAIN: example.com
workflow:
rules:
- if: '$DOMAIN == "example.com"'
- when: always
before_script:
- echo "before-script!!"
variables:
DOMAIN: example.com
workflow:
rules:
- if: '$DOMAIN == "example.com"'
when: always
- when: never
stages:
- build
- test
- codescan
- deploy
build:
before_script:
- echo "before-script in job"
stage: build
script:
- echo "mvn clean "
- echo "mvn install"
- ech "$DOMAIN"
after_script:
- echo "after script in buildjob"
rules:
- exists:
- Dockerfile
when: on_success
allow_failure: true
- changes:
- Dockerfile
when: manual
- when: on_failure
unittest:
stage: test
script:
- ech "run test"
when: delayed
start_in: '5'
allow_failure: true
retry:
max: 1
when:
- script_failure
timeout: 1 hours 10 minutes
deploy:
stage: deploy
script:
- echo "hello deploy"
- sleep 2;
rules:
- if: '$DOMAIN == "example.com"'
when: manual
- if: '$DOMAIN == "aexample.com"'
when: delayed
start_in: '5'
- when: on_failure
codescan:
stage: codescan
script:
- echo "codescan"
- sleep 5;
when: on_success
parallel: 5
after_script:
- echo "after-script"
- ech
继续阅读

我的微信
这是我的微信扫一扫
评论