Jenkins+github的一次定时构建示例

  首先说明,我的电脑环境是windows,所以以下的示例是基于windows10 X64。

一、新建任务,填写名称,选择类型,点击左下角的【确定】

二、配置

1、General

2、源码管理

  之前在github上配置了公钥(配置的东西看这里https://www.cnblogs.com/zichuan/p/9274785.html)这里要拉取github的代码,需要配置私钥,点击Add,弹窗中填写数据。

3、构建触发器

  这里我用的是定时任务,一般项目也用的这个选项吧。

扫描二维码关注公众号,回复: 2182580 查看本文章

4、构建环境

  这个模块默认即可,这个示例用不到

5、构建

6、构建后操作

  我这里设置的比较简单,就是发送邮件。

三、查看构建的结果

  以上设置完成之后,点击【保存】,点击左边菜单栏的【立即构建】,可以查看构建的结果。

  以上,在整个示例过程中,我遇到了一个坑,说大不大,说小不小。我只能说,windows和Linux还是区别的,下面来说说这个坑的发生过程:

1、我是windows环境,然后在构建的时候选择了执行shell脚本,然后改了很多地方,还是没解决,报错方式是这样的:

[0716_test] $ sh -xe C:\WINDOWS\TEMP\jenkins1910652898694296835.sh
The system cannot find the file specified
FATAL: 命令执行失败
java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
Caused: java.io.IOException: Cannot run program "sh" (in directory "C:\Program Files (x86)\Jenkins\workspace\0716_test"): CreateProcess error=2, 系统找不到指定的文件。
    at java.lang.ProcessBuilder.start(Unknown Source)
    at hudson.Proc$LocalProc.<init>(Proc.java:249)
    at hudson.Proc$LocalProc.<init>(Proc.java:218)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
    at hudson.Launcher$ProcStarter.start(Launcher.java:449)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
    at hudson.model.Run.execute(Run.java:1794)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Build step '执行 shell' marked build as failure
Finished: FAILURE

  找了我半个多小时,然后在这里找到了比较明确的说明以及解决方案:https://stackoverflow.com/questions/30374998/run-a-command-shell-in-jenkins。但是我试了添加系统环境变量和更改Jenkins的shell配置这两种方法都没成功,还是算了,老老实实选择“执行windows批处理命令”。有兴趣的看客可以试试,成功了给我留个言即可,在此谢过。

——日月盈昃,辰宿列张

猜你喜欢

转载自www.cnblogs.com/zichuan/p/9318149.html