使用Cron表达式指定执行时间。
# 格式
# ┌──分(0 - 59)
# │ ┌──时(0 - 23)
# │ │ ┌──日(1 - 31)
# │ │ │ ┌─月(1 - 12)
# │ │ │ │ ┌─星期(0 - 6,表示从周日到周六)
# │ │ │ │ │
# * * * *
# 每日 01:00
0 1 * * *
# 这个时候Jenkins 会提示我们使用下面的语法H 1 * * *
# 可能有大量的job 被设定在每日01:00执行
# H - jenkins可以自动安排执行顺序,减轻压力
* * * * * # 每分钟执行 这个时候我们要忽略下面的提示我们想要的就是每分钟执行
# Do you really mean "every minute" when you say "* * * * *"? Perhaps you meant "H * * * *" to poll once per hour
首先安装插件:
2 我们通过发送
安装插件以后我们获取
# 获取crumb
curl -u "jenkins:jenkins" 'http://ip/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
# Jenkins-Crumb:dcaad0c0555a9369b2874d4a6d8870b9f55d34510e9b2d537ef4cbd905ff7825
# 保存crumb
crumb=$(curl -u "jenkins:1234" -s 'http://10.0.0.215:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
#触发Jobs
curl -u "jenkins:1234" -H "$crumb" -X POST http://ip/job/maven-job/build?delay=0sec
首先进入仓库:
Gitlab默认使用了hashed storage,可以在 Main menu > Admin > Overview > Projects下
选中项目,找到 Gitaly relative path
然后区对应的路,创建钩子文件。
Git server hooks
可以定义 pre-receive, post-receive, update 等多种 Git server-side hooks
- applypatch-msg
- pre-applypatch
- post-applypatch
- pre-commit
- prepare-commit-msg
- commit-msg
- post-commit
- pre-rebase
- post-checkout
- post-merge
- pre-receive
- update
- post-receive
- post-update
- pre-auto-gc
- post-rewrite
- pre-push
pre-receive
,没有扩展名。pre-receive.d
。# 新建custom_hooks目录
mkdir custom_hooks
cd custom_hooks
vi post-receive
在post-receive
中写入,刚刚crumbIssuer的方式
#! /bin/bash
crumb=$(curl -u "jenkins:1234" -s 'http://10.0.0.215:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
curl -u "jenkins:1234" -H "$crumb" -X POST http://10.0.0.215:8080/job/maven-job/build?delay=0sec
保存,赋予执行权限
chmod u+x post-receive