jenkins配置前端自动部署
创建凭证(gitee/github/gitlab(用户名+密码))
如果密码错误自动构建会报错:
Started by user admin
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/docs
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
The recommended git tool is: NONE
using credential 55ca1747-69da-4472-9daa-0c5473402583
Cloning the remote Git repository
Cloning repository https://gitee.com/Yang_02/cy-docs.git
> init /var/jenkins_home/workspace/docs # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /var/jenkins_home/workspace/docs
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:1079)
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:825)
at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1220)
at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1310)
at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1277)
at hudson.scm.SCM.checkout(SCM.java:540)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1250)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522)
at hudson.model.Run.execute(Run.java:1833)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:446)
Caused by: hudson.plugins.git.GitException: Error performing git command: init /var/jenkins_home/workspace/docs
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2864)
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2768)
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2763)
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2052)
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:1077)
... 13 more
Caused by: java.io.IOException: Cannot run program "" (in directory "/var/jenkins_home/workspace/docs"): error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(Unknown Source)
at java.base/java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:994)
at hudson.Launcher$ProcStarter.start(Launcher.java:506)
at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2841)
... 17 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(Unknown Source)
at java.base/java.lang.ProcessImpl.start(Unknown Source)
... 24 more
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE
Plugins下的Available plugins下安装插件
SSH server 、publish Over SSH、SSH Build Agents plugin
ssh server 配置
System 下配置服务器账号密码
Tools下安装Nodejs
新建项目
1.
2.git
3.选择node版本
4.执行 shell
node -v
npm -v
npm config set registry https://registry.npmmirror.com/
npm install
npm run build
5.配置打包后自动部署到服务器位置
成功的控制台输出
Started by user admin
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/docs
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
The recommended git tool is: NONE
using credential e23e4531-3163-44cc-87f3-b9a933cdd047
Cloning the remote Git repository
Cloning repository https://gitee.com/Yang_02/cy-docs.git
> git init /var/jenkins_home/workspace/docs # timeout=10
Fetching upstream changes from https://gitee.com/Yang_02/cy-docs.git
> git --version # timeout=10
> git --version # 'git version 2.39.5'
using GIT_ASKPASS to set credentials
> git fetch --tags --force --progress -- https://gitee.com/Yang_02/cy-docs.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://gitee.com/Yang_02/cy-docs.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 561705e099e1804170d0b597418ef66bd6e0828f (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 561705e099e1804170d0b597418ef66bd6e0828f # timeout=10
Commit message: "更新文档"
First time build. Skipping changelog.
Unpacking https://nodejs.org/dist/v23.1.0/node-v23.1.0-linux-x64.tar.gz to /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/v23.1.0 on Jenkins
[docs] $ /bin/sh -xe /tmp/jenkins17827783038979128632.sh
+ node -v
v23.1.0
+ npm -v
10.9.0
+ npm config set registry https://registry.npmmirror.com/
+ npm install
(node:11988) ExperimentalWarning: CommonJS module /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/v23.1.0/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/v23.1.0/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
added 123 packages in 4m
40 packages are looking for funding
run `npm fund` for details
+ npm run build
> build
> vitepress build docs
[32m[1mvitepress[22m v1.5.0[39m
- building client + server bundles...
[33m
The language 'ba' is not loaded, falling back to 'txt' for syntax highlighting.[39m
[33m
The language 'bas' is not loaded, falling back to 'txt' for syntax highlighting.[39m
[33m
The language 'bas' is not loaded, falling back to 'txt' for syntax highlighting.[39m
[33m
The language 'bas' is not loaded, falling back to 'txt' for syntax highlighting.[39m
[33m
The language 'ba' is not loaded, falling back to 'txt' for syntax highlighting.[39m
[33m
The language 'bas' is not loaded, falling back to 'txt' for syntax highlighting.[39m
[32m✓[0m building client + server bundles...
- rendering pages...
[32m✓[0m rendering pages...
build complete in 5.45s.
SSH: Connecting from host [cba571e6d378]
SSH: Connecting with configuration [我的服务器] ...
SSH: Disconnecting configuration [我的服务器] ...
SSH: Transferred 45 file(s)
Build step 'Send files or execute commands over SSH' changed build result to SUCCESS
Finished: SUCCESS