首先说明,个人电脑环境是windows,因此如下的示例是基于windows10 X64。html
1、新建任务,填写名称,选择类型,点击左下角的【肯定】java
2、配置python
一、Generalgit
二、源码管理github
以前在github上配置了公钥(配置的东西看这里http://www.javashuo.com/article/p-hxmmbixp-ea.html)这里要拉取github的代码,须要配置私钥,点击Add,弹窗中填写数据。shell
三、构建触发器windows
这里我用的是定时任务,通常项目也用的这个选项吧。ui
四、构建环境spa
这个模块默认便可,这个示例用不到3d
五、构建
六、构建后操做
我这里设置的比较简单,就是发送邮件。
3、查看构建的结果
以上设置完成以后,点击【保存】,点击左边菜单栏的【当即构建】,能够查看构建的结果。
以上,在整个示例过程当中,我遇到了一个坑,说大不大,说小不小。我只能说,windows和Linux仍是区别的,下面来讲说这个坑的发生过程:
一、我是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批处理命令”。有兴趣的看客能够试试,成功了给我留个言便可,在此谢过。
补充:针对构建模块中的语句,此示例中是python xx.py,若是构建以后日志中提示“python不是内部或者外部命令”。请先在cmd中尝试执行python的命令(例python,回车。能够查看Python的版本)看是否成功。报错的缘由是执行Jenkins的系统用户环境变量中没有python的环境变量,因此解决方法是:在系统环境变量path中添加python.exe这个文件的路径!
——日月盈昃,辰宿列张