使用访问令牌push代码
方法一(推荐)
Jenkinsfile
1 | pipeline { |
2 | agent { |
3 | docker { |
4 | image 'lenyuadmin/hexo' |
5 | } |
6 |
|
7 | } |
8 | stages { |
9 | stage('检出') { |
10 | steps { |
11 | checkout([$class: 'GitSCM', branches: [[name: env.GIT_BUILD_REF]], userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]]) |
12 | } |
13 | } |
14 | stage('环境') { |
15 | steps { |
16 | echo '构建中...' |
17 | sh 'npm config set registry http://mirrors.cloud.tencent.com/npm/' |
18 | sh 'npm install' |
19 | sh 'hexo -v' |
20 | echo '构建完成.' |
21 | } |
22 | } |
23 | stage('生产') { |
24 | steps { |
25 | echo '生产中...' |
26 | sh 'hexo clean' |
27 | sh 'hexo g' |
28 | echo '生产完成.' |
29 | } |
30 | } |
31 | stage('部署') { |
32 | steps { |
33 | echo '部署中...' |
34 | dir(path: 'public') { |
35 | sh 'ls' |
36 | sh 'git init' |
37 | sh 'git config user.name $USER_NAME' |
38 | sh 'git config user.email $USER_EMAIL' |
39 | sh 'git add -A' |
40 | sh 'git commit -m \'init\'' |
41 | sh 'git push -u -f "$USER_PROJECT" master:master' |
42 | } |
43 | echo '部署完成' |
44 | } |
45 | } |
46 | } |
47 | } |
配置环境变量
1 | USER_NAME = 你的昵称 |
2 |
|
3 | USER_EMAIL = 你的邮箱 |
4 |
|
5 | USER_PROJECT = 提交的地址 |
6 |
|
7 | USER_PROJECT地址的规则是 |
8 | https://子账号名:子账号的密码@项目https地址 |
原文链接
方法二
_config.yml
1 | deploy: |
2 | type: git |
3 | repo: repo: https://令牌用户名:访问令牌@e.coding.net/mcontext/mContext/Blog.git |
4 | branch: master |
令牌用户名和访问令牌在 头像->个人设置->访问令牌
JenkinsfileContent
1 | pipeline { |
2 | agent any |
3 | stages { |
4 | stage('检出') { |
5 | steps { |
6 | checkout([$class: 'GitSCM', branches: [[name: env.GIT_BUILD_REF]], |
7 | userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]]) |
8 | } |
9 | } |
10 | stage('构建') { |
11 | steps { |
12 | echo '构建中...' |
13 | sh 'node -v' |
14 | sh 'npm install -g hexo-cli' |
15 | sh 'npm install hexo --save' |
16 | sh 'npm install -g hexo-generator-searchdb' |
17 | sh 'npm install -g' |
18 | echo '构建完成.' |
19 | } |
20 | } |
21 | stage('测试') { |
22 | steps { |
23 | echo '单元测试中...' |
24 | sh 'hexo clean' |
25 | sh 'hexo g ' |
26 | echo '单元测试完成.' |
27 | } |
28 | } |
29 | stage('部署') { |
30 | steps { |
31 | echo '部署中...' |
32 | sh 'npm install hexo-deployer-git --save' |
33 | sh 'hexo deploy' |
34 | echo '部署完成' |
35 | } |
36 | } |
37 | } |
38 | } |
参考:使用Coding进行Hexo项目的持续集成