1.局部/全局环境变量
stages:- testing # stage编排- build- deployvariables:global_var: "全部变量" #全部变量build_image:stage: buildvariables: #局部环境变量my_name: "局部环境变量" tags:- shell script:- echo "打包镜像"- echo "$my_name" #打印局部环境变量- echo "$global_var" #打印全局环境变量deploy_to_qa:stage: deploytags:- shell script:- echo "部署到QA"
运行结果:
2.判断语句
stages:- testing # stage编排- build- deployworkflow:rules:- if: $CI_COMMIT_BRANCH == "dev" #如果提交的分支,等于dev,则执行(类似if...else)when: always - when: never #类似elserun_test: #Jobstage: testingtags:- shell #Gitlab-runner script:- echo "执行测试."- chmod +x ./run.sh # 给run.sh加可执行权限- ./run.sh # 运行外部文件./run.sh
执行结果:(不做,因为在master分支提交的)
3.自定义系统 全局变量
stages:- testing # stage编排- build- deployrun_test: #Jobstage: testingtags:- shell #Gitlab-runner script:- echo "执行测试."- chmod +x ./run.sh # 给run.sh加可执行权限- ./run.sh # 运行外部文件./run.sh- echo "$BAIDU" # 打印自定义系统全局变量
执行结果: