官方文檔
https://docs.gitlab.com/ce/ci/yaml/README.html
通用示例
stages: #定義步驟列表類型,從上往下執行
- build
- release
build: #job名字
stage: build #和stages對應的名字
image: i.harbor.xxxx.com/public/node:10-alpine-node-sass #使用的鏡像,如果不寫,就是註冊runner默認鏡像
script: #鏡像執行命令,這裏我構建node的東西
- npm install && npm run build
- ls -al
artifacts: #構建完成後,構建的產物(目錄或者文件),丟給後面的步驟
paths:
- .nuxt/
- .
tags: #選擇runner的tag
- rancher
- dev
only: #構建選擇,如下,只選擇develop的分支構建
- develop
release:
stage: release
before_script: #執行前執行
- eval $(ssh-agent -s)
- echo "$HIFIVE_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
image: i.harbor.xxxx.net/public/ssh-client:rsync
script:
- ssh -p 22 -o StrictHostKeyChecking=no [email protected] -- "pm2 del hifive-openmusic-web|true"
- rsync -azP --exclude=".gitignore" --exclude=".git" --delete ./ [email protected]:/data/wwwroot/hifive-openmusic-web/
- ssh -p 22 -o StrictHostKeyChecking=no [email protected] -- "ls -al /data/wwwroot/hifive-openmusic-web/"
- ssh -p 22 -o StrictHostKeyChecking=no [email protected] -- "cd /data/wwwroot/hifive-openmusic-web/ && pm2 start npm --watch --name hifive-openmusic-web -- run start "
tags:
- rancher
- dev
only:
- develop
when: on_success #只有當上一個job成功才執行,默認就是on_success
name | 說明 |
---|---|
script | 由Runner執行的Shell腳本。 |
image | 使用docker鏡像。也可用:image:name和image:entrypoint。image: centos:7 |
services | 使用docker services圖像。也可用:services:name,services:alias,services:entrypoint,和services:command。 |
before_script | 覆蓋在作業之前執行的一組命令。 |
after_script | 覆蓋作業後執行的一組命令。 |
stages | 定義管道中的階段。列表 |
stage | 定義作業階段(默認值:) test。 |
only | 創建作業時限制(常用於分支選擇)。也可用:only:refs,only:kubernetes,only:variables,和only:changes。常見用法:only: - branches #所有分支 - tags - /^issue-.*$/ #正則匹配issue-的分支 - master #master分支 |
except | 在未創建作業時限制(常用於排除分支)。也可用:except:refs,except:kubernetes,except:variables,和except:changes。 |
tags | 用於選擇Runner的標籤列表常用範例:tags: - runner - dev |
allow_failure | 讓工作失敗。失敗的作業無助於提交狀態。 |
when | 什麼時候開始工作。參數: on_success:只有當前一個階段的所有工作都成功時(或者因爲它們被標記而被認爲是成功的allow_failure)才執行工作 。這是默認值。 on_failure:僅當前一階段的至少一個作業失敗時才執行作業。 always:無論先前階段的工作狀態如何,都可以執行工作。 manual:手動執行作業(在GitLab 8.10中添加)。 |
environment | 作業部署到的環境的名稱。也可用:environment:name,environment:url,environment:on_stop,和environment:action。 |
cache | 後續運行之間應緩存的文件列表。也可用:cache:paths,cache:key,cache:untracked,和cache:policy。 |
artifacts | (構建產物交給下一個階段)成功附加到作業的文件和目錄列表。也可用:artifacts:paths,artifacts:name,artifacts:untracked,artifacts:when,artifacts:expire_in,artifacts:reports,和artifacts:reports:junit。在GitLab 企業版,這些都是可供選擇:artifacts:reports:codequality,artifacts:reports:sast,artifacts:reports:dependency_scanning,artifacts:reports:container_scanning,artifacts:reports:dast,artifacts:reports:license_management,artifacts:reports:performance和artifacts:reports:metrics。常用範例: artifacts: #構建完成後,構建的產物(目錄或者文件),丟給後面的步驟 paths: - .nuxt/ - . |
dependencies | 作業所依賴的其他作業,以便您可以在它們之間傳遞工件。 |
coverage | 給定作業的代碼覆蓋率設置。 |
retry | 在發生故障的情況下,可以自動重試作業的次數和次數。 |
parallel | 應該並行運行多少個作業實例。 |
trigger | 定義下游管道觸發器。 |
include | 允許此作業包含外部YAML文件。也可用:include:local,include:file,include:template,和include:remote。 |
extends | 此作業將繼承的配置條目。 |
pages | 上傳作業結果以用於GitLab Pages。 |
variables | 在作業級別定義作業變量。 |
我的網站
愛運維:https://www.iyunw.cn
python粉絲:https://www.pythonfans.cn