Merge branch 'main' of https://git.xhupo.com/iProbe/jenkins-cron
This commit is contained in:
commit
16c053bacb
2 changed files with 107 additions and 0 deletions
86
jenkins-cron.yaml
Normal file
86
jenkins-cron.yaml
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
kind: ConfigMap
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
config.yaml: |-
|
||||||
|
gradle:
|
||||||
|
caches:
|
||||||
|
- /home/gradle/caches
|
||||||
|
|
||||||
|
jenkins:
|
||||||
|
schema: https
|
||||||
|
url: jenkins-ops.shasoapp.com
|
||||||
|
user: admin ## 需要替换
|
||||||
|
token: xxxx ## 需要替换
|
||||||
|
number: lastBuild
|
||||||
|
default_parameters:
|
||||||
|
- only_build: true ## jenkins中配置
|
||||||
|
|
||||||
|
jobs: # 需要编译的项目列表
|
||||||
|
- echo-rework
|
||||||
|
- turing-message-center
|
||||||
|
- turing-payment-service
|
||||||
|
- turing-dmp
|
||||||
|
- turing-faceup
|
||||||
|
- turing-fluenty
|
||||||
|
- turing-maxxhealth
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: CronJob
|
||||||
|
apiVersion: batch/v1
|
||||||
|
metadata:
|
||||||
|
name: jenkins-cron
|
||||||
|
namespace: ops
|
||||||
|
annotations:
|
||||||
|
description: 定时清理gradle缓存并刷新
|
||||||
|
spec:
|
||||||
|
schedule: 0 3 * * * # 每天3点开始执行
|
||||||
|
concurrencyPolicy: Replace
|
||||||
|
suspend: false
|
||||||
|
jobTemplate:
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
app: jenkins-cron
|
||||||
|
version: v1
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: gradle
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: pvc-jenkins-m2 ## gradle使用的缓存目录
|
||||||
|
- name: config
|
||||||
|
configMap:
|
||||||
|
name: jenkins-cron-cm
|
||||||
|
defaultMode: 420
|
||||||
|
containers:
|
||||||
|
- name: jenkins-cron
|
||||||
|
image: swr.cn-east-3.myhuaweicloud.com/turingsyn/ops/jenkins-cron:v1.9
|
||||||
|
command:
|
||||||
|
- /app/jenkins-cron
|
||||||
|
resources: {}
|
||||||
|
volumeMounts:
|
||||||
|
- name: gradle
|
||||||
|
mountPath: /home/gradle
|
||||||
|
- name: config
|
||||||
|
mountPath: /app/config.yaml
|
||||||
|
subPath: config.yaml
|
||||||
|
terminationMessagePath: /dev/termination-log
|
||||||
|
terminationMessagePolicy: File
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
terminationGracePeriodSeconds: 30
|
||||||
|
dnsPolicy: ClusterFirst
|
||||||
|
securityContext: {}
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: default-secret ## 镜像仓库认证文件
|
||||||
|
schedulerName: default-scheduler
|
||||||
|
dnsConfig:
|
||||||
|
options:
|
||||||
|
- name: single-request-reopen
|
||||||
|
successfulJobsHistoryLimit: 3
|
||||||
|
failedJobsHistoryLimit: 1
|
||||||
|
|
21
readme.md
21
readme.md
|
@ -1 +1,22 @@
|
||||||
|
## 原理
|
||||||
|
jenkins-cron项目访问到jenkins使用gradle编译项目的缓存目录,删除缓存目录中的文件,达到清理缓存的目的。
|
||||||
|
触发jenkins中相应job编译,刷新缓存。
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
* 前提 *
|
||||||
|
* 1. jenkins中对应的job需要配置布尔类型的only_build参数,当该参数为true时,仅编译,不进行发布。 *
|
||||||
|
* 2. jenkins中对应的job中需要配置触发远程构建时的身份令牌,目前只支持同一个身份令牌。 *
|
||||||
|
|
||||||
|
## 编译
|
||||||
|
```shell
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o jenkins-cron
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o jenkins-cron
|
||||||
|
```
|
||||||
|
|
||||||
|
## 打包镜像
|
||||||
|
```shell
|
||||||
|
docker build -t swr.cn-east-3.myhuaweicloud.com/turingsyn/ops/jenkins-cron:v1.9 .
|
||||||
|
docker push swr.cn-east-3.myhuaweicloud.com/turingsyn/ops/jenkins-cron:v1.9
|
||||||
|
```
|
||||||
|
|
||||||
|
## k8s使用
|
||||||
|
* 需要挂载gradle使用的缓存目录
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue