0%

使用Coding进行Hexo项目的持续集成

使用访问令牌push代码

方法一(推荐)

Jenkinsfile

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
35
36
37
38
39
40
41
42
43
44
45
46
47
pipeline {
agent {
docker {
image 'lenyuadmin/hexo'
}

}
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 'npm config set registry http://mirrors.cloud.tencent.com/npm/'
sh 'npm install'
sh 'hexo -v'
echo '构建完成.'
}
}
stage('生产') {
steps {
echo '生产中...'
sh 'hexo clean'
sh 'hexo g'
echo '生产完成.'
}
}
stage('部署') {
steps {
echo '部署中...'
dir(path: 'public') {
sh 'ls'
sh 'git init'
sh 'git config user.name $USER_NAME'
sh 'git config user.email $USER_EMAIL'
sh 'git add -A'
sh 'git commit -m \'init\''
sh 'git push -u -f "$USER_PROJECT" master:master'
}
echo '部署完成'
}
}
}
}

配置环境变量

1
2
3
4
5
6
7
8
USER_NAME = 你的昵称

USER_EMAIL = 你的邮箱

USER_PROJECT = 提交的地址

USER_PROJECT地址的规则是
https://子账号名:子账号的密码@项目https地址

原文链接

方法二

_config.yml

1
2
3
4
deploy:
type: git
repo: repo: https://令牌用户名:访问令牌@e.coding.net/mcontext/mContext/Blog.git
branch: master

令牌用户名和访问令牌在 头像->个人设置->访问令牌

JenkinsfileContent

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
35
36
37
38
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 'node -v'
sh 'npm install -g hexo-cli'
sh 'npm install hexo --save'
sh 'npm install -g hexo-generator-searchdb'
sh 'npm install -g'
echo '构建完成.'
}
}
stage('测试') {
steps {
echo '单元测试中...'
sh 'hexo clean'
sh 'hexo g '
echo '单元测试完成.'
}
}
stage('部署') {
steps {
echo '部署中...'
sh 'npm install hexo-deployer-git --save'
sh 'hexo deploy'
echo '部署完成'
}
}
}
}

参考:使用Coding进行Hexo项目的持续集成