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

前置步骤

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

刷新cdn

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

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 '刷新完毕'
}
}
}
}

参数说明

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的参数均为要刷新的目录

单独使用

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开源协议