GitLab流水线的一个小示例

88 阅读1分钟

项目根目录创建流水线所使用的文件,文件名必须为.gitlab-ci.yml

touch .gitlab-ci.yml

修改文件的内容如下

before_script:
  - echo "before script"  # 每次job运行时候会输出,
  
variables:
   DOMAIN: example.com  # 定义了一个全局的变量
stages:
  - build
  - deploy

build-code:  # 一个作业(job),该作业名称为build-code
  before_script:
    - echo "before script"  # script运行之前会执行
  stage: build
  tags:
    - deploy  # 使用该runner执行构建
  only:
    - main  # 只构建master分支
  script:
    - echo "mvn clean"
    - echo "mvn install"
    - echo "$DOMAIN"
  after_script:
    - echo "after script"  # 作业执行完之后会执行
    
deploy-app:  # 在该job中未定义before_script和afeter_script默认会走全局的
  stage: deploy # 其中一个stage
  tags:
    - deploy
  only:
    - main
  script:
    - echo "hello deploy"

after_script:
  - echo "after script"  # 作业执行完之后会执行

提交到仓库,可以看到流水线在跑了

image.png

查看输出

image.png

image.png

image.png