hugo自动化发布文章测试页面
hugo自动化发布文章页面
jenkins pipeline如下:
pipeline {
agent any
environment {
GITLAB_CREDENTIAL_ID = '3581665b-ddfc-4d20-96bd-da85de7809dc'
GITLAB_URL = 'https://github.com/xinxiaoyu/blog-hugo'
CredentialId= '3581665b-ddfc-4d20-96bd-da85de7809dc'
PROJECT_NAME = 'blog'
web_site = 'xinxiaoyu.github.io'
BRANCH = 'main'
}
parameters {
// List Git Branches Parameter PlugIn
listGitBranches branchFilter: 'refs/heads/(.*)',
defaultValue: 'main',
name: 'BRANCH',
type: 'PT_BRANCH',
remoteURL: "https://github.com/xinxiaoyu/blog-hugo.git",
credentialsId: '3581665b-ddfc-4d20-96bd-da85de7809dc',
selectedValue: 'DEFAULT',
sortMode: 'ASCENDING',
quickFilterEnabled: true
}
stages {
stage ('Checkout') {
steps {
git(credentialsId: "${env.CredentialId}", url: "${env.GITLAB_URL}.git", branch: "${env.BRANCH}", changelog: true, poll: false)
}
}
stage('Build') {
steps {
echo 'Building...'
sh "chmod 777 ./${env.PROJECT_NAME}"
dir("./${env.PROJECT_NAME}") {
sh '/usr/bin/hugo'
}
}
}
stage('copy to web') {
steps {
sh '[ -d "xinxiaoyu.github.io" ] && rm -rf xinxiaoyu.github.io && echo "done" || echo "not done"'
sh 'git clone https://github.com/xinxiaoyu/xinxiaoyu.github.io.git'
sh "cp -rf ./${env.PROJECT_NAME}/public/* ./xinxiaoyu.github.io/"
}
}
stage('deploy') {
steps {
dir("./xinxiaoyu.github.io/") {
sh 'ls'
sh 'git config --global user.email "1248247511@qq.com"'
sh 'git config --global user.name "xinxiaoyu"'
sh 'git add *'
sh 'git commit -m "123"'
withCredentials([usernamePassword(credentialsId: "${env.CredentialId}",
usernameVariable: 'username',
passwordVariable: 'password')]){
sh("git push https://$username:$password@github.com/xinxiaoyu/xinxiaoyu.github.io.git")
}
}
}
}
}
}