gridea发布博客文章之后,内容推送到coding仓库的master分支后,触发同步,就会自动同步到github gitee。

coding的持续集成使用的是Jenkinsfile实现的pipeline,可以根据自己的需要定制功能,这里我写一写coding和github gitee同步的方法。

项目设置


持续集成 构建计划

设置使用静态的Jenkinsfile配置后保存


编写实现脚本


这里我给出实现coding与github gitee 同步的脚本内容,使用时需要将,用户名,token,仓库名,进行对应更改后保存即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 'git fetch https://用户名:token@github.com/用户名/仓库名.git'
sh 'git push -f https://用户名:token@github.com/用户名/仓库吗.git HEAD:master'
echo '已完成文件推送.'
}
}
}
}

默认情况是代码推送到master分支时触发,在以上内容编写保存完成后,可以进行一次仓库同步或者手动触发一次构建,测试功能是否正常。如果需要同步到其他地方,则需要对,用户名丶密钥丶仓库地址丶进行修改。

评论