GitLab CI/CD All In One
GitLab CI/CD All In One
Webhooks
Webhooks enable you to send notifications to web applications in response to events in a group or project.
We recommend using an integration in preference to a webhook.
https://gitlab.com/help/user/project/integrations/webhooks
Integrations ✅
Integrations enable you to make third-party applications part of your GitLab workflow.
If the available integrations don't meet your needs, consider using a webhook.
https://gitlab.com/xgqfrms/xyz-ui/-/settings/integrations
https://docs.gitlab.com/ee/user/project/integrations/overview.html
Jenkins
https://gitlab.com/xgqfrms/xyz-ui/-/integrations/jenkins/edit
Jira
https://gitlab.com/xgqfrms/xyz-ui/-/integrations/jira/edit
gitlab
https://docs.gitlab.com/ee/ci/yaml/
https://docs.gitlab.com/ee/ci/yaml/gitlab_ci_yaml.html
scripts / jobs / stages / pipeline
The scripts
are grouped into jobs
, and jobs run as part of a larger pipeline
.
You can group multiple independent jobs into stages
that run in a defined order.
The CI/CD configuration needs at least one job that is not hidden.
You should organize your jobs
in a sequence that suits your application and is in accordance with the tests you wish to perform.
To visualize the process, imagine the scripts you add to jobs are the same as CLI commands you run on your computer.
When you add a .gitlab-ci.yml
file to your repository, GitLab detects it and an application called GitLab Runner runs the scripts defined in the jobs.
.gitlab--web-app-ci.yml
# gitlab-ci template repo
include:
- project: infra/pipeline
file: 2022/.gitlab-ci.yml
2022/.gitlab-ci.yml
.gitlab-ci.yml
stages:
- build
- test
build-code-job:
stage: build
script:
- echo "Check the ruby version, then build some Ruby project files:"
- ruby -v
- rake
test-code-job1:
stage: test
script:
- echo "If the files are built successfully, test some files with one command:"
- rake test1
test-code-job2:
stage: test
script:
- echo "If the files are built successfully, test other files with a different command:"
- rake test2
Dockerfile.ci
FROM nginx:latest
COPY dist/ /data/www/web-app
COPY nginx.conf /etc/nginx/conf.d/default.conf
nginx.conf
server {
listen 80;
server_name _;
root /data/www/web-app;
index index.html;
location / {
try_files $uri $uri/ /index.html =404;
index index.html;
add_header Cache-Control no-store,max-age=0;
}
location /fs/ {
proxy_pass https://open.feishu.cn/;
}
}
github
on
jobs
steps
# This is a basic workflow to help you get started with Actions
name: FS_ROBOT
# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the main branch
push:
branches: [ main ]
schedule:
- cron: '00 08,20 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
hello-job:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# notice job
wx-robot:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v1
# 自定义 env, $GITHUB_ENV => ${{env.REPORT_DATE}}
- name: 'Get Date'
run: echo "REPORT_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T')" >> $GITHUB_ENV
# 自定义 env, $GITHUB_ENV => ${{env.WEBHOOK_KEY}}
- name: 'set webhook key'
run: echo "WEBHOOK_KEY=${{secrets.WEB_HOOK_KEY}}" >> $GITHUB_ENV
# 自动发送打开通知
- name: 'Send Notice'
run: bash ./src/robot.sh
# set env
# - name: 'set env'
# run: export WX_ROBOT_KEY=${{secrets.WX_ROBOT_KEY}}
# - name: 'get env'
# run: echo $WX_ROBOT_KEY
# 自动发送打开通知
# - name: 'Send Notice'
# run: bash ./src/robot.sh $WX_ROBOT_KEY
# 自动发送打开通知
# - name: 'Send Notice'
# run: bash ./src/robot.sh env.WEBHOOK_KEY env.REPORT_DATE
demo
https://gitlab.com/xgqfrms/xyz-ui/-/hooks
https://github.com/xgqfrms/fs-robot-notice/blob/main/.github/workflows/robot.yml
Alpine Linux
alpine / 高山
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16006648.html
未经授权禁止转载,违者必究!