e.coding.net上用官方提供的demo自动将博客代码推至腾讯COS后,发现涉及云函数刷新CDN的地方计费方式过于恐怖,所以用自己的方式去刷新CDN

前置步骤

直到刷新CDN之前与demo保持一致

刷新cdn

coding->项目构建设置中添加一步刷新CDN:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pipeline {
agent any
stages {
stage('检出') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: env.GIT_BUILD_REF]],
userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]
])
}
}
stage('部署到腾讯云存储') {
steps {
echo '部署中...'
sh 'coscmd config -a $TENCENT_SECRET_ID -s $TENCENT_SECRET_KEY -b $TENCENT_BUCKET -r $TENCENT_REGION'
sh 'rm -rf .git'
sh 'coscmd upload -r ./ /'
echo '部署完成'
}
}
stage('刷新CDN') {
steps {
echo '准备刷新'
sh 'git clone https://github.com/BestBurning/tencentcloud.git'
dir(path: './tencentcloud') {
sh 'mvn clean package '
sh 'java -jar ./target/tencentcloud-1.0-SNAPSHOT.jar $TENCENT_SECRET_ID $TENCENT_SECRET_KEY $TENCENT_REGION https://yourdomain/'
}
echo '刷新完毕'
}
}
}
}

参数说明

1
2
3
4
java -jar ./target/tencentcloud-1.0-SNAPSHOT.jar $TENCENT_SECRET_ID $TENCENT_SECRET_KEY $TENCENT_REGION urlIndex1 urlIndex2 urlIndex3 ...

e.g.
java -jar ./target/tencentcloud-1.0-SNAPSHOT.jar $TENCENT_SECRET_ID $TENCENT_SECRET_KEY $TENCENT_REGION https://di1shuai.com/
  1. $TENCENT_SECRET_ID - 腾讯云SECRET_ID
  2. $TENCENT_SECRET_KEY - 腾讯云SECRET_KEY
  3. $TENCENT_REGION - 腾讯云区域
  4. >=4的参数均为要刷新的目录

单独使用

1
2
3
git clone https://github.com/BestBurning/tencentcloud.git
mvn clean package
java -jar ./target/tencentcloud-1.0-SNAPSHOT.jar $TENCENT_SECRET_ID $TENCENT_SECRET_KEY $TENCENT_REGION https://yourdomain/

源码

cdn刷新源码开源在Github

开源协议

采用MIT开源协议