Gitlab中Pipeline语法四

Gitlab中Pipeline语法

cache

cache:paths

  • 在job build中定义缓存,将会缓存target目录下的所有*.jar文件
  • 当全局定义了cache:paths会被job中覆盖.以下实例将缓存target目录
buld:
  script: build
  cache:
    paths:
      - target/*.jar
#设置key可以解决cache被覆盖
cache:
 paths:
   - my/files

build:
  script:
    - echo "build"
  cache:
    key: build
    paths:
      - target/

cachefiles文件变化自动创建缓存

files: 文件发生变化自动重新生成缓存(files最多指定两个文件),提交时检查指定文件.根据指定的文件生成秘钥计算SHA检验和,如果文件未发生改变值为default.

cache:
  key:
   files:
     - Gemfile.lock
     - package.json
  paths:
    - vendor/ruby
    - node_modules

cacheprefix 组合生成SHA校验和

prefix: 允许给定prefix的值与指定文件生成的秘钥组合

cache:
  key:
   files:
     - Gemfile.lock
    prefix: ${CI_JOB_NAME}
  paths:
    - vendor/ruby
rspec:
  script:
    - bundle exec rspec

cache:policy 缓存策略

默认: 在执行时开始下载文件,并在结束时重新上传文件/
policy: pull 跳过下载步骤, policy: push 跳过上传下载步骤


before_script:
  - echo "before_script!!!"

variables:
  DOMAIN: example.com

cache:
  paths:
    - target/

stages:
  - build
  - test
  - deploy

build:
  before_script:
    - echo "before_script in build job"
  stage: build
  tags:
    - build
  only:
    - master
  script:
    - ls
    - id
    - mvn clean package -DskipTests
    - ls target
    - echo "$DOMAIN"
    - false && true ; exit_code=$?
    - if [ $exit_code -ne 0 ]; then echo "Previous command failed"; fi;
    - sleep 2; 
  after_script:
    - echo "after_script in build job"
  
 
unittes:
  stage: test
  tags:
    - build
  only:
    - master
  script:
    - echo "run test"
    - echo 'test' >> a.txt
    - ls target
  retry:
    max: 2
    when:
      - script_failure

deploy:
  stage: deploy
  tags:
    - build
  only:
    - master
  script:
    - echo "run deploy"
    - ls target
  retry:
    max: 2
    when:
      - script_failure
 
after_script:
  - echo "after_script"

你可能感兴趣的:(gitlab,开发语言,linux)